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

Support AbortSignal.throwIfAborted() #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DLiblik
Copy link

@DLiblik DLiblik commented Sep 23, 2022

Part of the spec and very useful in looping procedural code:

// somewhere inside some func that takes a signal
for(const item of items) {
  signal?.throwIfAborted();
  // part 1 of expensive per-item code here...
  signal?.throwIfAborted();
  // part 2 of expensive per-item code here...
}

Part of the spec and very useful in looping procedural code:

```ts
// somewhere inside some func that takes a signal
for(const item of items) {
  signal?.throwIfAborted();
  // part 1 of expensive per-item code here...
  signal?.throwIfAborted();
  // part 2 of expensive per-item code here...
}
```
@onestep
Copy link

onestep commented Jan 12, 2023

I would also ask to add support for reason property to support passing custom exceptions to abort signal.

@onestep
Copy link

onestep commented Jan 12, 2023

Example implementation in nodejs - https://github.com/nodejs/node/pull/40951/files.

Copy link
Owner

@benlesh benlesh left a comment

Choose a reason for hiding this comment

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

Sorry for the ridiculously late review. This is a good add, but a little incorrect. The problem is it has to throw whatever was passed to abort() on the abort controller. Which is super weird, but there it is.

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

Successfully merging this pull request may close these issues.

3 participants