Reactivecocoa-publish、multicast、replay、replayLast
发布时间:2020-12-15 04:49:32 所属栏目:百科 来源:网络整理
导读:// - replay 总是收取最后的内容,而并不执行signal 123456789101112131415161718192021222324 __block int num = 0 ; RACSignal * signal = [ [ RACSignal createSignal :^ RACDisposable * ( id subscriber ) { num ++ ; NSLog ( @ "Increment num to: %i"
//-replay 总是收取最后的内容,而并不执行signal
Incrementnumto:1 Startsubscriptions S1:1 S2:1
S3:1
http://spin.atomicobject.com/2014/06/29/replay-replaylast-replaylazily/
-replay 总是取出第一订阅者取到的
所有结果
-replayLast 总是取出第一个订阅者取到的
最后一个结果
-replayLazily有点说不上来
replayLazily does not subscribe to the signal immediately – it lazily waits until there is a “real” subscriber. But replay subscribes immediately. So as you point out,with replayLazily the “A” value would not be sent to subscribers of the signal because it was sent before there was anything listening.
RACMulticastConnection public connect
当一个信号被订阅了几次,那么它将会执行几次,见下方代码:
RACSignal
*signal1 = [
RACSignal
defer
:^
*{
NSLog ( @"print signal1" ); return [ RACSignal : @"hello" ]; }]; [signal1 subscribeNext :^( id x) { @"first %@" ,x); }]; [signal1 @"second %@"
}];
2015-06-05 14:35:38.149 DemoCategorizer[15252:2226982] print signal1
2015-06-05 14:35:38.149 DemoCategorizer[15252:2226982] first hello 2015-06-05 14:35:38.149 DemoCategorizer[15252:2226982] print signal1
2015-06-05 14:35:38.149 DemoCategorizer[15252:2226982] second hello
那么,我打算某个网络操作只做一次,然后多个订阅者都可以收到消息,怎么做?
@"signal1"
];
}]; RACMulticastConnection *connection = [signal1 publish ]; [connection. signal @"first next value = %@" @"second next value = %@"
[connection connect];
2015-06-05 14:38:48.528 DemoCategorizer[15848:2239991] print signal1
2015-06-05 14:38:48.528 DemoCategorizer[15848:2239991] first next value = signal1
2015-06-05 14:38:48.528 DemoCategorizer[15848:2239991] second next value = signal1
signal1只是被执行了一次,神奇不? 详见
http://www.jianshu.com/p/a0a821a2480f
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |