Last active
December 26, 2015 23:09
-
-
Save jonsterling/7228372 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RACCommand *example = [[RACCommand alloc] initWithSignalBlock:^(id input) { | |
return [RACSignal createWithBlock:^(id<RACSubscriber> subscriber){ | |
[subscriber sendCompleted]; | |
return nil; | |
}]; | |
]; | |
// Now, how will I know when each task has completed? | |
// I certainly cannot tell from `example.executionSignals.flatten`. | |
RACSignal *completions = [example.executionSignals flattenMap:^(RACSignal *transaction) { | |
return [transaction then:^{ | |
[RACSignal return:RACUnit.defaultUnit] | |
}]; | |
}]; | |
RACCommand *resetCommand = [[RACCommand alloc] initWithSignalBlock:^(id input) { | |
return [RACSignal return:[RACUnit defaultUnit]]; | |
}]; | |
RACSignal *incrementing = [completions mapReplace:^(NSNumber *count) { | |
return @(count.integerValue + 1); | |
}]; | |
RACSignal *resetting = [resetCommand.executionSignals.flatten mapReplace:^(NSNumber *count) { | |
return @0; | |
}]; | |
RACSignal *transformers = [RACSignal merge:@[ incrementing, resetting ]]; | |
RACSignal *runningCount = [transformers scanWithStart:@0 reduce:^(NSNumber *count, NSNumber *(^transformer)(NSNumber *)) { | |
return transformer(count); | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment