Skip to content

Instantly share code, notes, and snippets.

@slabko
Last active September 27, 2016 08:01
Show Gist options
  • Save slabko/546de430a16994a5da8e to your computer and use it in GitHub Desktop.
Save slabko/546de430a16994a5da8e to your computer and use it in GitHub Desktop.
RACCommand category for tracking completion
#import "RACCommand.h"
@interface RACCommand (ARLCompletedSignal)
@property (nonatomic, readonly) RACSignal *completed;
@end
#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