简体   繁体   中英

Can I merge RAC signals but still get each error individually?

Update:

Instead of:

RACSignal * mergedItemsSignals = [RACSignal merge:itemSignalsArray];

generate your new signal like this:

RACSignal * mergedItemsSignals = [RACSignal merge:[itemSignalsArray.rac_sequence map:^id(RACSignal * signal) {
        return [signal materialize];
    }]];

And when you subscribe you expect RACEvents which you can distinguish using [RACEvent eventType] .


With an array of signals I want to be able to process individually each next and each error . But I'm struggling to find the appropiate operator. So far it seems the proper choice is

merge : Returns a signal that passes through values from each of the given signals, and sends completed when all of them complete. If any signal sends an error, the returned signal sends error immediately.

So, it seems that I need something similar. I want to receive all errors, but the unified signal should keep working instead of finishing on the first one.

I tried using 'combineLatest' as well, but this only forwards events once each signal has sent something, and I want to start forwarding as soon as possible for each signal.

Hope it's clear enough, and someone can point me in the right direction. Thanks in advance!

A signal can only error once, so you'll need a way to convert those error s into next s. Fortunately, materialize does just that -- given a signal, it gives you a signal of events from that signal. You can then split that into two signals, for the errors, and nexts, -- or just process them in a single block.

So you can take a list of signals, map materialize , and then merge the resultant mapped signals.

- (RACSignal *)mergeEvents:(NSArray *)signals {
    return [RACSignal merge:[signals.rac_sequence map:^(RACSignal *signal) {
        return [signal materialize];
    }]];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM