副作用的操作——doNext:
// 副作用的操作doNext:后期需要深入的理解
RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
[subscriber sendNext:@1];
[subscriber sendNext:@2];
[subscriber sendNext:@4];
[subscriber sendCompleted];
return [RACDisposable disposableWithBlock:^{
NSLog(@"完成");
}];
}];
RACSignal *signalB = [signalA doNext:^(id x) {
NSLog(@"doNext:%@",x);
}];
[[signalB subscribeNext:^(id x) {
NSLog(@"subscribeNext:%@",x);
}] dispose];
2021-04-15 11:30:46.809094+0800 xxxxxx[3504:1044105] doNext:1
2021-04-15 11:30:46.809133+0800 xxxxxx[3504:1044105] subscribeNext:1
2021-04-15 11:30:46.809143+0800 xxxxxx[3504:1044105] doNext:2
2021-04-15 11:30:46.809152+0800 xxxxxx[3504:1044105] subscribeNext:2
2021-04-15 11:30:46.809161+0800 xxxxxx[3504:1044105] doNext:4
2021-04-15 11:30:46.809169+0800 xxxxxx[3504:1044105] subscribeNext:4
2021-04-15 11:30:46.810342+0800 xxxxxx[3504:1044105] 完成
网友评论