Skip to content

Instantly share code, notes, and snippets.

@asci
Created March 12, 2018 14:17
Show Gist options
  • Save asci/2d83b40cb943bb9a713b544ce0a319af to your computer and use it in GitHub Desktop.
Save asci/2d83b40cb943bb9a713b544ce0a319af to your computer and use it in GitHub Desktop.
Observable from Promise
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