I think I found a solution. The trick is to combine the cancel signal into a tick signal, then take X-samples. End subscribers will receive the following event each time the tick signal goes off and ends when the take is complete. Cancellation can be accomplished by sending an error to the cancel timer.
__block RACSubject *cancelTimer = [RACSubject subject]; RACSubscribable *tickWithCancel = [[RACSubscribable interval:1.0] merge:cancelTimer]; RACSubscribable *timeoutFiveSec = [tickWithCancel take:5]; [timeoutFiveSec subscribeNext:^(id x) { NSLog(@"Tick"); } error:^(NSError *error) { NSLog(@"Cancelled"); } completed:^{ NSLog(@"Completed"); [alert dismissWithClickedButtonIndex:-1 animated:YES]; }];
To activate the cancellation, do the following.
[cancelTimer sendError:nil]; // nil or NSError
source share