Domanda

A very simple question and I'm overseeing probably a key method in RAC.

Say I've got this simple signal

RACSignal *signal = [[RACSignal return:@"hello"] delay:10]

How can I without changing above code create a new signal which sends completed when any value is passed (in this case @"hello" after 10 seconds)?

È stato utile?

Soluzione 2

Some alternativs

RACSignal *completeSignal = [[signal take:1] ignoreValues];

RACSignal *completeSignal = [signal flattenMap:^(id value) {
    return [RACSignal empty];
}];

RACSignal *completeSignal = [signal flattenMap:^(id value) {
    return nil;
}];

Altri suggerimenti

You could also just use -take: with a parameter of 1:

RACSignal *originalSignal = [[RACSignal return:@"hello"] delay:10];
RACSignal *completesOnFirstValue = [originalSignal take:1];

If you don't want the signal to send a value before it completes, you can use -flattenMap: as in your response, or you can use -takeUntil::

RACSignal *completesBeforeFirstValue = [originalSignal takeUntil:originalSignal];

(The -takeUntil: operator will cause the signal to complete when the trigger signal fires before the value is delivered.)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top