-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
lib: add aborted() utility function #46494
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
Conversation
|
I think this would require further discussion since the conversation on the original issue stopped at 2021, nonetheless have tried to implement the discussed details until then and have added tests cc @benjamingr, @jasnell |
aduh95
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would need documentation, as well as tests with invalid types/values to ensure we correctly validate the input.
|
Yes adding to those tests, Docs can I update after this is confirmed that this change is acceptable? |
| const ac = new AbortController(); | ||
| aborted(ac.signal, {}).then(common.mustNotCall()); | ||
| setImmediate(() => { | ||
| global.gc(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does GC accomplish here? That the aborted() promise is collected before abort() is called?
I don't know if that kind of GC observability is a good thing. Maybe it works now but GC changes can break such patterns. Looks fragile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically want to cleanup the empty object to check if the listener is removed when the resource is cleaned by the gc, unsure of any other ways to test this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's just for testing, then it's probably fine. I mean, it could still break in the future but we can revisit if and when that happens.
I'd advise against documenting that behavior though. It's simply not very robust.
benjamingr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM, missing docs (this should be marked as experimental, and as for where it should live I'll ping some TSC folk and ask)
|
Have added to the docs, @benjamingr @aduh95 |
Co-authored-by: Antoine du Hamel <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
| */ | ||
| async function aborted(signal, resource) { | ||
| if (signal === undefined) { | ||
| throw new ERR_INVALID_ARG_TYPE('signal', 'AbortSignal', signal); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have added this check since turns out changing the condition in validateAbortSignal() immediately results in the build breaking, so i assume its probably not a bug but would like a review here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like a common pattern across to the codebase to check for undefined and then validate the signal so i think its probably fine?
|
Landed in 6d584ae |
Fixes: #37220
Refs: #36607