Search code examples
swiftreactive-cocoareactive-cocoa-4

What happens to individual failures with combineLatest?


If i have two SignalProducers (really they are API service requests so they only send 'next' once), and combine them with combineLatest (as i want to dismiss a loading spinner once both finish), what happens if one of them fails? Or both fail?

Does 'failed' get called (once or twice?) on the combined signal?

If one fails and the other succeeds, will 'next' be called on the combined signal?


Solution

  • Failure of any signal will cause the entire combined signal to error and stop subscription.

    If one signal sends its first next and the other signal sends an error as its first value then the next will be lost, combineLatest: is only called once all signals send their first next value.

    subscribeError: is only called once. Errors work in a monadic way where they bubble up the chain and stop the whole signal.

    If you want to subvert this then you can use the catch:, catchTo:, or retry methods to handle errors.

    (Sorry for talking about the Objective-C methods, I don't know the Swift syntax).