值操作—mapReplace:
// 逐一操作单个信号值,统一替换为一个值
// map遇到错误的时候会无一例外的返回这个错误,并立即结束信号。
RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
[subscriber sendNext:@1];
[subscriber sendNext:@2];
[subscriber sendNext:@3];
[subscriber sendNext:@4];
[subscriber sendCompleted];
return [RACDisposable disposableWithBlock:^{
NSLog(@"完成");
}];
}];
RACSignal *signalB = [signalA mapReplace:@8];
[[signalB subscribeNext:^(id x) {
NSLog(@"subscribeNext:%@",x);
}] dispose];
执行结果:
2021-04-14 14:38:17.763081+0800 xxxxx[3049:927533] subscribeNext:8
2021-04-14 14:38:17.763162+0800 xxxxx[3049:927533] subscribeNext:8
2021-04-14 14:38:17.763194+0800 xxxxx[3049:927533] subscribeNext:8
2021-04-14 14:38:17.763218+0800 xxxxx[3049:927533] subscribeNext:8
2021-04-14 14:38:17.764598+0800 xxxxx[3049:927533] 完成
网友评论