父類 | NSObject |
---|---|
子類 | RACImmediateScheduler |
RACQueueScheduler |
|
RACSubscriptionScheduler |
|
RACTestScheduler |
|
類含義 | RAC調度類 |
遵循的協議 | 無 |
屬性 | 無 |
顯示網絡下載的圖片網絡
RAC(self.imageView, image) = [[RACSignal startEagerlyWithScheduler:[RACScheduler schedulerWithPriority:RACSchedulerPriorityBackground] block:^(id <RACSubscriber> subscriber) { NSError *error; NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://ww3.sinaimg.cn/bmiddle/7128be06jw1ei4hfthoj3j20hs0bomyd.jpg"] options:NSDataReadingMappedAlways error:&error]; if(error) { [subscriber sendError:error]; } else { [subscriber sendNext:[UIImage imageWithData:data]]; [subscriber sendCompleted]; } }] deliverOn:[RACScheduler mainThreadScheduler]];
這段代碼會在後臺線程當即發起一個請求,而後傳遞到主線程上更新UI併發
+ (RACSignal *)startEagerlyWithScheduler:(RACScheduler *)scheduler block:(void (^)(id<RACSubscriber> subscriber))block;
- (RACSignal *)deliverOn:(RACScheduler *)scheduler
+ (RACScheduler *)mainThreadScheduler;
主線程調度app
+ (RACScheduler *)currentScheduler;
當前隊列調度異步
+ (RACScheduler *)scheduler;
這方法至關於執行了[RACScheduler schedulerWithPriority:RACSchedulerPriorityDefault];
async
+ (RACScheduler *)schedulerWithPriority:(RACSchedulerPriority)priority;
指定等級的異步併發隊列,這個其實調用的是spa
[[RACTargetQueueScheduler alloc] initWithName:name targetQueue:dispatch_get_global_queue(priority, 0)];
其中RACTargetQueueScheduler
類的父類是RACQueueScheduler
,並且RACQueueScheduler
中有個方法是:線程
- (RACDisposable *)schedule:(void (^)(void))block { NSCParameterAssert(block != NULL); RACDisposable *disposable = [[RACDisposable alloc] init]; dispatch_async(self.queue, ^{ if (disposable.disposed) return; [self performAsCurrentScheduler:block]; }); return disposable; }
能夠看到最終用的仍是dispatch_async
的異步調用code