You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
constcontroller=newAbortController();constresponse=awaitesClient.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.
Currently, the
TransportRequestPromise
type is an extension of the built-inPromise
type, which contains anabort
method to programmatically cancel the request. Extending the nativePromise
makes it difficult to chain/wrap or useasync
/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) byfetch
:It sounds like @delvedor has been considering this since it is likely to land natively in Node [1]. From our conversations:
[1] nodejs/node#33527
The text was updated successfully, but these errors were encountered: