Skip to content

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

@vgavro

Description

@vgavro

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)
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions