美文网首页
RAC的doNext副作用

RAC的doNext副作用

作者: 凯司机 | 来源:发表于2021-04-21 09:19 被阅读0次

    副作用的操作——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] 完成

    相关文章

      网友评论

          本文标题:RAC的doNext副作用

          本文链接:https://www.haomeiwen.com/subject/fcrxrltx.html