Last active
September 27, 2016 08:01
-
-
Save slabko/546de430a16994a5da8e to your computer and use it in GitHub Desktop.
RACCommand category for tracking completion
This file contains hidden or 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
#import "RACCommand.h" | |
@interface RACCommand (ARLCompletedSignal) | |
@property (nonatomic, readonly) RACSignal *completed; | |
@end |
This file contains hidden or 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
#import <ReactiveCocoa/ReactiveCocoa.h> | |
#import "RACCommand+ARLCompletedSignal.h" | |
@implementation RACCommand (ARLCompletedSignal) | |
- (RACSignal *)completed | |
{ | |
RACSignal *executing = self.executing; | |
RACSignal *signals = self.executionSignals; | |
RACSignal *errors = self.errors; | |
RACSignal *startingExecution = [RACSignal combineLatest:@[executing, [signals take:1]] | |
reduce:^id(NSNumber *executing, id _){ return executing; }]; | |
return [[[startingExecution | |
ignore:@NO] | |
flattenMap:^RACStream *(id value) { | |
RACSignal *comletedOrFailed = [[[executing ignore:@YES] subscribeOn:[RACScheduler scheduler]] | |
map:^id(id value) { return @YES; }]; | |
RACSignal *failed = [[errors subscribeOn:[RACScheduler scheduler]] | |
map:^id(id value) { return @NO; }]; | |
return [[RACSignal merge:@[comletedOrFailed, failed]] take:1]; | |
}] replayLast]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment