public
Last active

ReactiveCocoa: How to initialize a RACScheduler with a serially executing GCD queue.

  • Download Gist
RACSerialScheduler.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
@interface SerialScheduler ()
@property (nonatomic, strong) RACScheduler *serialScheduler;
@end
@implementation SerialScheduler
/**
* This scheduler executes signals one a 1-by-1 basis.
* Use it with ReactiveCocoa when you want to handle signal execution serially.
*/
- (RACScheduler *)serialScheduler
{
if(!_serialScheduler){
_serialScheduler = [[RACTargetQueueScheduler alloc] initWithName:@"QueueName"
targetQueue:dispatch_queue_create("QueueName", DISPATCH_QUEUE_SERIAL)];
}
return _serialScheduler;
}
@end

Usage:

...
    @weakify(self)
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        @strongify(self)
        return [self.serialScheduler schedule:^{
            // do something
        }];
    }]
...

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.