美文网首页
RAC的takeUntil、takeUntilReplaceme

RAC的takeUntil、takeUntilReplaceme

作者: 凯司机 | 来源:发表于2021-05-08 18:02 被阅读0次

    组合操作——takeUntil、takeUntilReplacement:

    // 组合操作——takeUntil:
    // 组合操作——takeUntil:照相
    RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
      [subscriber sendNext:@1];
      [subscriber sendNext:@2];
      [subscriber sendNext:@3];
      [subscriber sendNext:@4];
      [subscriber sendNext:@5];
      [subscriber sendCompleted];
      return [RACDisposable disposableWithBlock:^{
          NSLog(@"signalA完成");
      }];
    }];
    
    RACSignal *signalB = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
      return [RACDisposable disposableWithBlock:^{
          [subscriber sendNext:@3];
          [subscriber sendNext:@4];
          [subscriber sendNext:@5];
          NSLog(@"signalB完成");
      }];
    }];
    [signalB subscribeNext:^(id x) {
      NSLog(@"subscribeNext:%@",x);
    }];
    
    RACSignal *signalC = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
      return [RACDisposable disposableWithBlock:^{
          [subscriber sendNext:@3];
          [subscriber sendNext:@4];
          [subscriber sendNext:@5];
          NSLog(@"signalC完成");
      }];
    }];
    [signalC subscribeNext:^(id x) {
      NSLog(@"subscribeNext:%@",x);
    }];
    
    RACSignal *signalD = [[signalA takeUntil:signalB] takeUntil:signalC];
    
    [[signalD subscribeNext:^(id x) {
      NSLog(@"subscribeNext:%@",x);
    }] dispose];
    

    2021-04-23 15:55:03.653943+0800 XXXXXX[2982:994188] subscribeNext:1

    2021-04-23 15:55:03.654017+0800 XXXXXX[2982:994188] subscribeNext:2

    2021-04-23 15:55:03.654044+0800 XXXXXX[2982:994188] subscribeNext:3

    2021-04-23 15:55:03.654065+0800 XXXXXX[2982:994188] subscribeNext:4

    2021-04-23 15:55:03.654089+0800 XXXXXX[2982:994188] subscribeNext:5

    2021-04-23 15:55:03.654226+0800 XXXXXX[2982:994188] signalB完成

    2021-04-23 15:55:03.654278+0800 XXXXXX[2982:994188] signalC完成

    2021-04-23 15:55:03.654310+0800 XXXXXX[2982:994188] signalA完成

    相关文章

      网友评论

          本文标题:RAC的takeUntil、takeUntilReplaceme

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