Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-[RACMulticastConnection connect] not working as expected. #47

Open
nverinaud opened this issue Nov 28, 2016 · 0 comments
Open

-[RACMulticastConnection connect] not working as expected. #47

nverinaud opened this issue Nov 28, 2016 · 0 comments

Comments

@nverinaud
Copy link

When calling connect it connects and subscribes correctly to the underlying signal.
Then, disposing the returned RACDisposable unsubscribe correctly from the underlying signal.
Then, reconnecting no longer subscribe to the underlying signal when it should to.

Here is a code you can paste in a sample project to verify.

- (void)testRx
{
    NSLog(@"Current Time: %@", NSDate.date);
    RACSignal *source = [RACSignal interval:1 onScheduler:[RACScheduler scheduler]]; //creates a sequence
    
    RACMulticastConnection *hot = [source publish]; // convert the sequence into a hot sequence
    
    RACDisposable *subscription1 = [hot.signal subscribeNext:^(id  _Nullable x) {
        NSLog(@"1: Next(%@)", x);
    } error:^(NSError * _Nullable error) {
        NSLog(@"1: Error(%@)", error);
    } completed:^{
        NSLog(@"1: Completed");
    }];
    
    NSLog(@"Current Time after 1st subscription: %@", NSDate.date);
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        __block RACDisposable *connectionDisposable = [hot connect]; // hot is connected to source and starts pushing value to subscribers
        NSLog(@"Current Time after Connect: %@", NSDate.date);
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            NSLog(@"Current Time just before 2nd subscription: %@", NSDate.date);
            
            RACDisposable *subscription2 = [hot.signal subscribeNext:^(id  _Nullable x) {
                NSLog(@"2: Next(%@)", x);
            } error:^(NSError * _Nullable error) {
                NSLog(@"2: Error(%@)", error);
            } completed:^{
                NSLog(@"2: Completed");
            }];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                NSLog(@"Disconnecting");
                [connectionDisposable dispose];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    NSLog(@"Reconnecting");
                    connectionDisposable = [hot connect]; // this should resubscribe and broadcast values !
                    
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        NSLog(@"Ending");
                        [subscription1 dispose];
                        [subscription2 dispose];
                        [connectionDisposable dispose];
                    });
                });
            });
        });
    });
}

You can test the equivalent in C# using the code sample from here.

I will work on a PR to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant