Skip to content

Instantly share code, notes, and snippets.

@banjun
Created February 21, 2018 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banjun/140c1cabb9616160d750f893c1eb3434 to your computer and use it in GitHub Desktop.
Save banjun/140c1cabb9616160d750f893c1eb3434 to your computer and use it in GitHub Desktop.
create SignalProducer that create Future with the autoclosure on start and send a result to the inner observer
extension SignalProducer {
// create SignalProducer that create Future with the autoclosure on start and send a result to the inner observer
init(_ future: @escaping @autoclosure () -> Future<Value, Error>) {
self.init { observer, _ in
future()
.onSuccess {
observer.send(value: $0)
observer.sendCompleted()}
.onFailure {
observer.send(error: $0)}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment