-
Notifications
You must be signed in to change notification settings - Fork 725
Description
Currently, the TransportRequestPromise type is an extension of the built-in Promise type, which contains an abort method to programmatically cancel the request. Extending the native Promise makes it difficult to chain/wrap or use async/await`.
As an alternative (or additional) approach, I'd like to suggest using the AbortController/AbortSignal approach used natively (supported in most modern browsers, polyfill available) by fetch:
const controller = new AbortController();
const response = await esClient.search(params, {
signal: controller.signal
});
// Then, if we need to abort for some reason, maybe in an event handler:
controller.abort();It sounds like @delvedor has been considering this since it is likely to land natively in Node [1]. From our conversations:
That’s something I’ve been thinking for a while, as a similar api is landing to node core.
Unfortunately we can’t drop the support for the .abort method as it would be a breaking change, but we can support both and deprecate the old one. I’ve already implemented it in userland libraries (https://github.com/nodejs/undici), the main reason why the client has an .abort method, is because the legacy one had it. I want to see how Node.js will end up supporting this, to avoid creating an api not compatible with the rest of the ecosystem.