Created
January 29, 2018 10:46
-
-
Save Marcocanc/c17f373852526a8084d4df3b9155c7af to your computer and use it in GitHub Desktop.
Inject an Error on a given Signal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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