objective c - ReactiveCocoa merge that completes when input signal completes -
in reactivecocoa, there mechanism similar merge:
completes when of signals being merged complete?
i found workaround involves concatenating input signal [racsignal return:foo]
, adding take:1
after merge, seems rather long-winded. there simpler way?
not built-in reactivecoca. should define in helper category on racsignal
, long-windedness hidden behind nice method abstraction.
here's (untested) example using materialize
, give signal of signal events don't need append onto input signals:
+ (racsignal *)sheepishmerge:(nsarray *)signals { racsequence *completions = [signals.rac_sequence map:^(racsignal *signal) { return [[signal materialize] filter:^(racevent *event) { return event.eventtype == raceventtypecompleted; }]; }]; racsignal *firstcompletion = [[racsignal merge:completions] take:1]; return [[racsignal merge:signals] takeuntil:firstcompletion]; }
Comments
Post a Comment