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

Request gets aborted after success when using Timeout #72

Closed
tomvardasca opened this issue Mar 10, 2023 · 2 comments
Closed

Request gets aborted after success when using Timeout #72

tomvardasca opened this issue Mar 10, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@tomvardasca
Copy link

Hi,

Thank you a lot for this library!

Looked at the code in https://github.com/connor4312/cockatiel/blob/master/src/TimeoutPolicy.ts#L100 and noticed that we trigger an abort in the finally.
This behavior makes this signal unusable for the fetch API https://developer.mozilla.org/en-US/docs/Web/API/AbortController#instance_methods

AbortController.abort()
Aborts a DOM request before it has completed. This is able to abort fetch requests, consumption of any response bodies, and streams.

This way in node.js when we try to consume the response. It is already aborted.

Would it be possible to have an option to skip this?

Kind Regards,
Tomé

@connor4312
Copy link
Owner

connor4312 commented Mar 10, 2023

Changing this behavior would be breaking, but in 3.1.0 I've added a new option you can use like so:

timeout(
  ({ signal }) => fetch('https://example.com', { signal }),
  { strategy: 'aggressive', abortOnReturn: false /* <-- new */ },
)

@connor4312 connor4312 added the enhancement New feature or request label Mar 10, 2023
@tomvardasca
Copy link
Author

Thank you for adding an option!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants