Skip to content

Instantly share code, notes, and snippets.

@qwtel
Created June 3, 2018 03:55
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 qwtel/f897b46c2fa837fe7a0571f1deb8e7a6 to your computer and use it in GitHub Desktop.
Save qwtel/f897b46c2fa837fe7a0571f1deb8e7a6 to your computer and use it in GitHub Desktop.
function fetchRx(url, options) {
const controller = new AbortController();
const { signal } = controller;
return Observable.create(observer => {
fetch(url, { signal, ...options })
.then(x => observer.next(x))
.catch(x => observer.error(x))
.finally(() => observer.complete())
return () => controller.abort();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment