Why [RACLifting rac_liftSelector:] prints different results between cases A and B

Why [RACLifting rac_liftSelector:]

does it print different results between cases A and B

- (void)test
{
RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
    double delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [subscriber sendNext:@"A"];
    });
    return nil;
}];

RACSignal *signalB = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {


//        {//case A:
//            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//                [subscriber sendNext:@"B"];
//                [subscriber sendNext:@"Another B"];
//                [subscriber sendNext:@"Another Bbbbb"];
//            });
//        }


    {//case B:
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [subscriber sendNext:@"B"];
            [subscriber sendNext:@"Another B"];
            [subscriber sendNext:@"Another Bbbbb"];
        });
    }

    return nil;
}];

[self rac_liftSelector:@selector(doA:withB:) withSignals:signalA, signalB, nil];
}

- (void)doA:(NSString *)A withB:(NSString *)B
{
    NSLog(@"A:%@ and B:%@", A, B);
}

      

In the case of A and B, there is only one other: the delay time changes from 1 second to 3 seconds. But in case A it NSLog only once when

2015-07-16 10:55:28.837 ReactiveCocoa[2563:581353] A:A and B:Another Bbbbb

      

then in case B it NSLog three times like

2015-07-16 10:55:26.819 ReactiveCocoa[2563:581353] A:A and B:B
2015-07-16 10:55:28.836 ReactiveCocoa[2563:581353] A:A and B:Another B
2015-07-16 10:55:28.837 ReactiveCocoa[2563:581353] A:A and B:Another Bbbbb

      

Can anyone help me?

+3


source to share


1 answer


rac_liftSelector

works the same as it combineLatest

does for RACSignal

s, it waits until each signal dispatches an event before firing.

Because it signalA

does not fire within two seconds, and it only sends one event, in fact it is a gatekeeper doA:withB:

. No matter when it fires signalA

, its one event will never be lost.



signalB

on the other hand dispatches multiple events. Every event sent before every other fire RACSignal

(i.e. signalA

) will be lost except for the last event.

So while it rac_liftSelector

expects that in case A: for signalA

, events are not buffered. The first call doA:withB:

will only transmit the last event from each signal, but will continue to transmit each event for each signal from now on.

+2


source







All Articles