Skip to content

Instantly share code, notes, and snippets.

@Marcocanc
Created January 29, 2018 10:46
Show Gist options
  • Save Marcocanc/c17f373852526a8084d4df3b9155c7af to your computer and use it in GitHub Desktop.
Save Marcocanc/c17f373852526a8084d4df3b9155c7af to your computer and use it in GitHub Desktop.
Inject an Error on a given Signal
import ReactiveSwift
import Result
extension Signal {
func injectError(_ error: Error, on signal: Signal<(), NoError>) -> Signal<Value, Error> {
return Signal { observer, lifetime in
lifetime += signal.observe { event in
if event.value != nil {
observer.send(error: error)
}
}
lifetime += self.observe(observer)
}
}
}
extension SignalProducer {
func injectError(_ error: Error, on signal: Signal<(), NoError>) -> SignalProducer<Value, Error> {
return lift { $0.injectError(error, on: signal) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment