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

AbortController/AbortSignal support #1297

Closed
lukasolson opened this issue Sep 2, 2020 · 1 comment
Closed

AbortController/AbortSignal support #1297

lukasolson opened this issue Sep 2, 2020 · 1 comment

Comments

@lukasolson
Copy link
Member

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.

[1] nodejs/node#33527

@delvedor
Copy link
Member

Added support for AbortController in v8, see #1542.

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

2 participants