-
Notifications
You must be signed in to change notification settings - Fork 553
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
Expose a simple API to abort requests #164
Comments
+1! |
Then we change so that request no longer returns a Boolean? Or is the abort controller preferable? @mcollina does using a thenable instead of a promise in anyway affect async hooks, async await etc...? |
I think using abortcontroller is better. thenables can break the async context badly :( |
I think abortcontroller was discussed in node core somewhere. Will see if I can find that issue. |
See how it is implemented in https://github.com/jasnell/piscina#cancelable-tasks. I think it's a great way to add it. |
I'm going through the code for looking at how to implement the abort controller. if (opts.signal != null) {
opts.signal.on('abort', () => {
callback(new RequestAbortedError(), null)
})
} I don't know well enough the internals to know where and what to close/destroy to clean the used resources. @ronag can you point me in the right direction? Or if you want to take a stab, go for it! |
Yes, I agree.
I'll sort it out. If you'd like to build some additional test cases for it afterwards that would be great. |
In Got we just expose a |
What do you expose it on? Do you mean to return a thenable object, i.e. not a |
const promise = got('https://example.com'); // This is a promise
promise.cancel(); // The promise will throw an error |
@szmarczak Unfortunately that won't work as thenables break async context. |
@szmarczak @ronag that can work if you add a |
Are we fine with modifying the |
I would try to use the abortcontroller approach instead which is going to be more compatible with the rest of the ecosystem. |
With the current API it is not straightforward to abort a request, it would be great to expose a simple method to abort a request.
I was thinking about something very easy, for example:
With promises it should be a thenable.
For supporting this signature, we should transform the returned value in a thenable.
Otherwise, we could create something similar to the AbortController.
What do you think?
Related: #160
The text was updated successfully, but these errors were encountered: