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

fix -take: vs recursive -sendNext: #1877

Merged
merged 2 commits into from Apr 8, 2015
Merged

fix -take: vs recursive -sendNext: #1877

merged 2 commits into from Apr 8, 2015

Conversation

kentdotn
Copy link

@kentdotn kentdotn commented Apr 6, 2015

The following code causes infinite loop

RACSubject* subject = [RACSubject subject];
[[subject take:3] subscribeNext:^(NSNumber* value) {
    NSLog(@"value=%@", value);
    [subject sendNext:@(value.integerValue + 1)];
} completed:^{
    NSLog(@"completed");
}];
[subject sendNext:@100];

IIUC, this should output

value=100
value=101
value=102
completed

on debug console, then should stop.

@jspahrsummers
Copy link
Member

Recursive signals are kind of an antipattern in any case, but I agree that should not deadlock.

Can you please add a unit test that fails before the fix, and passes after it?

@kentdotn
Copy link
Author

kentdotn commented Apr 7, 2015

Alright, I've done.
Though, I'm not sure where the test case should be in.
RACStreamExamples.m should be better?

@jspahrsummers
Copy link
Member

This looks good as-is. Thanks! ✨

@jspahrsummers jspahrsummers merged commit fc716df into ReactiveCocoa:master Apr 8, 2015
jspahrsummers added a commit that referenced this pull request Apr 8, 2015
@jhollida24
Copy link

@jspahrsummers do you think you could elaborate a bit on why not to use recursive signals? (or point me towards something that already explains this well?)

@jspahrsummers
Copy link
Member

@jhollida24 The primary reason is that it's hard to statically determine whether they might recurse infinitely. It's a lot easier to just avoid that problem by not recursing in a signal graph.

Secondarily, it also introduces these sorts of concurrency issues. This fixes one particular case, but there may be others (we've never done an exhaustive audit to find out).

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

Successfully merging this pull request may close these issues.

None yet

3 participants