Skip to content

Instantly share code, notes, and snippets.

@hallski
Created December 6, 2012 23:22
Show Gist options
  • Save hallski/4229370 to your computer and use it in GitHub Desktop.
Save hallski/4229370 to your computer and use it in GitHub Desktop.
__block __typeof(self) weakSelf = self;
__block int tick = 0;
id<RACSignal> timer = [[[[RACSignal interval:1.0] startWithTrigger:self.startButton.rac_command] takeUntil:self.stopButton.rac_command] repeat];
[timer subscribeNext:^(id x) {
weakSelf.timerLabel.stringValue = [NSString stringWithFormat:@"%d", tick++];
}];
- (id<RACSignal>)startWithTrigger:(id<RACSignal>)signalTrigger
{
return [RACSignal createSignal:^(id<RACSubscriber> subscriber) {
__block RACDisposable *selfDisposable = nil;
__block RACDisposable *triggerDisposable = [signalTrigger subscribe:[RACSubscriber subscriberWithNext:^(id x) {
selfDisposable = [self subscribeNext:^(id x2) {
[subscriber sendNext:x2];
} error:^(NSError *error) {
[subscriber sendError:error];
} completed:^{
[subscriber sendCompleted];
}];
} error:^(NSError *error) {
} completed:^{
}]];
return [RACDisposable disposableWithBlock:^{
[triggerDisposable dispose];
[selfDisposable dispose];
}];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment