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

feat: add support for abort controller #92

Merged
merged 3 commits into from
Feb 2, 2023
Merged

Conversation

bjoerge
Copy link
Member

@bjoerge bjoerge commented Jan 19, 2023

Status: Approved, waiting for #86 to land before merging

This adds support for passing an AbortSignal to all the request methods exposed by the client. It will also work for the APIs that returns an observable as well. Although less useful since observables natively supports cancellation, I can't see the problem in having support for it, but would love to hear your thoughts.

Note: I've copied the approach ky uses when it comes to creating an AbortError that works in Node < v18

Example usage:

const abortController = new AbortController()
const request = client.fetch('*', {}, {signal: abortController.signal})

// this will abort the request and reject the `request` promise with an AbortError
abortController.abort()

Copy link
Member

@stipsan stipsan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it let's go 🚀 would love it if you add an example for it in the readme with how you use it in an await fetch 🧘

test/client.test.ts Outdated Show resolved Hide resolved
@bjoerge
Copy link
Member Author

bjoerge commented Jan 19, 2023

would love it if you add an example for it in the readme with how you use it in an await fetch 🧘

Great call! Added a couple of examples in 562b38b

@bjoerge bjoerge force-pushed the support-abort-controller branch 2 times, most recently from 1c83ea8 to 562b38b Compare January 19, 2023 14:55
Copy link
Member

@rexxars rexxars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thanks @bjoerge !

@bjoerge bjoerge merged commit 775b5b5 into main Feb 2, 2023
@bjoerge bjoerge deleted the support-abort-controller branch February 2, 2023 13:45
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2023

🎉 This PR is included in version 5.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants