标签:sub 发送数据 lock next ble code ica multicast 多少
-(void)_test5{ //弊端:有几个订阅者就会请求几次数据 // 1.创建信号 RACSignal *signal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { NSLog(@"发送热门模块的请求"); // 3.发送数据 [subscriber sendNext:@1]; return nil; }]; // 2.订阅信号 [signal subscribeNext:^(id x) { NSLog(@"订阅者一%@",x); }]; [signal subscribeNext:^(id x) { NSLog(@"订阅者二%@",x); }]; //弊端优化 // 不管订阅多少次信号,就会请求一次 // RACMulticastConnection:必须要有信号 // 1.创建信号 RACSignal *signal2 = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { // didSubscribe什么时候来:连接类连接的时候 NSLog(@"发送热门模块的请求"); [subscriber sendNext:@"热门模块的数据"]; return nil; }]; // 2.把信号转换成连接类 // 确定源信号的订阅者RACSubject // RACMulticastConnection *connection = [signal publish]; RACMulticastConnection *connection = [signal2 multicast:[RACReplaySubject subject]]; // 3.订阅连接类信号 [connection.signal subscribeNext:^(id x) { // nextBlock:发送数据就会来 NSLog(@"订阅者1:%@",x); }]; // 4.连接 [connection connect]; }
OC + RAC (五) RACMulticastConnection
标签:sub 发送数据 lock next ble code ica multicast 多少
原文地址:https://www.cnblogs.com/liuw-flexi/p/10805818.html