Created
March 12, 2018 14:17
-
-
Save asci/2d83b40cb943bb9a713b544ce0a319af to your computer and use it in GitHub Desktop.
Observable from Promise
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
export default function fromPromise(promise) { | |
return new Observable(observer => { | |
let active = true; | |
promise.then((...data) => { | |
if (active) { | |
observer.next(...data); | |
} | |
observer.complete(); | |
}).catch((...err) => observer.error(...err)); | |
return () => (active = false); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment