If a RACSignal sends next can I wrap it in something which sends completed instead?

StackOverflow https://stackoverflow.com/questions/22094861

  •  18-10-2022
  •  | 
  •  

Pregunta

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)?

¿Fue útil?

Solución 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;
}];

Otros consejos

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.)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top