The question is what, exactly, you mean with "does not throw an error".
The sequence of Events on a Signal
/SignalProducer
has a precisely defined semantic
Theres an arbitrary number of Value
(from 0 - x) Events, followed, eventually, by a completed
, failed
or interrupted
Event. After that there's no more events.
Generally you can say that most operators only operate on value
events and immediately propagate failed
events (without operating on them). If you're not sure in for a specific operator, take a look at the documentation of that operator which is very clear about the behaviour for failure events.
So one way to understand the question is to say when producerA
completes successfully (after an arbitrary number of value
Events), then start producerB
and if producerA
sends a failed
Event, then don't.
In that case, the then
operator is exactly what you need. It will start producerB
as soon as producerA
completes, but not if producerA
fails!
producerA.then(producerB)
.start(Signal.Observer(value: { value in
print("Value \(value)")
}, failed: {error in
print("Error \(error)")
}))
Note, that you dont want to use the flatMapError
here because that would (depending on how your error handling in the block looks) convert failed
events to value
Events which would trigger producerB
eventually.
Another way to understand the question is to say each event on producerA
that is not an error should trigger producerB
once
In that case, you would use flatMap
on the events of producerA
to return a producerB
for each event on producerA
. Note here, again, flatMap
propagates a failed
event immediately, so a failed
event on producerA
will cause the whole chain to fail without execution of producerB
producerA.flatMap(.concat) { _ in return producerB }
.start(Signal.Observer(value: { value in
print("Value \(value)")
}, failed: {error in
print("Error \(error)")
}))