Skip to content

Instantly share code, notes, and snippets.

@aceontech
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aceontech/8801996 to your computer and use it in GitHub Desktop.
Save aceontech/8801996 to your computer and use it in GitHub Desktop.
ReactiveCocoa: How to initialize a RACScheduler with a serially executing GCD queue.
@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
@aceontech
Copy link
Author

Usage:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment