美文网首页
RAC的冷信号 -> 热信号

RAC的冷信号 -> 热信号

作者: 凯司机 | 来源:发表于2021-05-17 09:48 被阅读0次

    冷信号 -> 热信号:

    // 冷信号 -> 热信号
    RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        [subscriber sendNext:@1];
        [subscriber sendNext:@11];
        [subscriber sendNext:@111];
        [subscriber sendNext:@1111];
        [subscriber sendCompleted];
        return [RACDisposable disposableWithBlock:^{
            NSLog(@"signalA1完成");
        }];
    }];
    
    RACSignal *signalB = [[signalA map:^id(id value) {
        return [[RACSignal return:value] delay:1];
    }] concat];
    
    RACSubject *speaker = [RACSubject subject];
    // 冷信号转变成一个热信号
    [signalB subscribe:speaker];
    [speaker subscribeNext:^(id x) {
        NSLog(@"1:%@",x);
    }];
    [speaker subscribeNext:^(id x) {
        NSLog(@"2:%@",x);
    }];
    [speaker subscribeNext:^(id x) {
        NSLog(@"3:%@",x);
    }];
    
    [speaker sendNext:@22];
    [speaker sendNext:@222];
    // 结果:
    

    2021-04-21 20:13:59.725736+0800 XXXXXX[2785:462147] 1:22

    2021-04-21 20:13:59.725775+0800 XXXXXX[2785:462147] 2:22

    2021-04-21 20:13:59.725786+0800 XXXXXX[2785:462147] 3:22

    2021-04-21 20:13:59.725797+0800 XXXXXX[2785:462147] 1:222

    2021-04-21 20:13:59.725806+0800 XXXXXX[2785:462147] 2:222

    2021-04-21 20:13:59.725814+0800 XXXXXX[2785:462147] 3:222

    2021-04-21 20:14:00.743432+0800 XXXXXX[2785:462147] 1:1

    2021-04-21 20:14:00.743628+0800 XXXXXX[2785:462147] 2:1

    2021-04-21 20:14:00.743745+0800 XXXXXX[2785:462147] 3:1

    2021-04-21 20:14:01.840378+0800 XXXXXX[2785:462147] 1:11

    2021-04-21 20:14:01.840572+0800 XXXXXX[2785:462147] 2:11

    2021-04-21 20:14:01.840685+0800 XXXXXX[2785:462147] 3:11

    2021-04-21 20:14:02.842987+0800 XXXXXX[2785:462147] 1:111

    2021-04-21 20:14:02.843184+0800 XXXXXX[2785:462147] 2:111

    2021-04-21 20:14:02.843298+0800 XXXXXX[2785:462147] 3:111

    2021-04-21 20:14:03.885937+0800 XXXXXX[2785:462147] 1:1111

    2021-04-21 20:14:03.886134+0800 XXXXXX[2785:462147] 2:1111

    2021-04-21 20:14:03.886256+0800 XXXXXX[2785:462147] 3:1111

    image.png image.png image.png image.png

    相关文章

      网友评论

          本文标题:RAC的冷信号 -> 热信号

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