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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions ReactiveCocoa/RACStream.m
Expand Up @@ -176,9 +176,13 @@ - (instancetype)take:(NSUInteger)count {
__block NSUInteger taken = 0;

return ^ id (id value, BOOL *stop) {
if (++taken >= count) *stop = YES;

return [class return:value];
if (taken < count) {
++taken;
if (taken == count) *stop = YES;
return [class return:value];
} else {
return nil;
}
};
}] setNameWithFormat:@"[%@] -take: %lu", self.name, (unsigned long)count];
}
Expand Down
28 changes: 28 additions & 0 deletions ReactiveCocoaTests/RACSignalSpec.m
Expand Up @@ -2913,6 +2913,34 @@ + (void)configure:(Configuration *)configuration {
expect(@(completed)).to(beTruthy());
});

qck_it(@"should complete take: even if the signal is recursive", ^{
RACSubject *subject = [RACSubject subject];
const NSUInteger number = 3;
const NSUInteger guard = number + 1;

NSMutableArray *values = NSMutableArray.array;
__block BOOL completed = NO;

[[subject take:number] subscribeNext:^(NSNumber* received) {
[values addObject:received];
if (values.count >= guard) {
[subject sendError:RACSignalTestError];
}
[subject sendNext:@(received.integerValue + 1)];
} completed:^{
completed = YES;
}];
[subject sendNext:@0];

NSMutableArray* expectedValues = [NSMutableArray arrayWithCapacity:number];
for (NSUInteger i = 0 ; i < number ; ++i) {
[expectedValues addObject:@(i)];
}

expect(values).to(equal(expectedValues));
expect(@(completed)).to(beTruthy());
});

qck_describe(@"+zip:", ^{
__block RACSubject *subject1 = nil;
__block RACSubject *subject2 = nil;
Expand Down