Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question - extend from native signal to use with fetch? #7

Open
vgavro opened this issue Apr 23, 2021 · 0 comments
Open

Question - extend from native signal to use with fetch? #7

vgavro opened this issue Apr 23, 2021 · 0 comments

Comments

@vgavro
Copy link

vgavro commented Apr 23, 2021

Greetings! thanks for really great and simple library, this is exactly how Promise Abort API should be implemented in my opinion! Simple, obvious and extremely useful!

I understand why we redefine AbortSignal and AbortController (because of abort(reason) lack, by the way - I think reason can be exposed also as signal.reason (in case of signal.aborted - like in https://github.com/getify/CAF#signalaborted-and-signalreason).

My question is about Fetch API from example. Why original signal can't be passed to Fetch API? Is it some interface incompatibility, or internal instanceof check? Even if it's impossible for some reason, IMHO example should explicitly explain why.

const promise = new AbortablePromise((resolve, reject, signal) => {
  const url = `/`;
  const controller = new AbortController();
  fetch(url, { signal: controller.signal }).then(resolve, reject);
  signal.onabort = controller.abort.bind(controller);
})
// --- Why not
const promise = new AbortablePromise((resolve, reject, signal) => {
  fetch(url, { signal }).then(resolve, reject)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant