Add support for AbortSignal in methods#42
Open
Lily0603 wants to merge 4 commits into
Open
Conversation
JaoodxD
suggested changes
Feb 19, 2026
Comment on lines
+70
to
+72
| signal.addEventListener('abort', () => { | ||
| reject(new Error(signal.reason)); | ||
| }); |
There was a problem hiding this comment.
We should also remove the abort listener if it hasn't fired but is no longer needed.
In cases like timeout or successful promise resolution, the abort event won't occur, yet the listener will still hold a reference to the signal and prevent it from being garbage collected.
We should introduce a cleanup step that removes the listener and call it on every exit path before resolving or rejecting
There was a problem hiding this comment.
Suggested change
| signal.addEventListener('abort', () => { | |
| reject(new Error(signal.reason)); | |
| }); | |
| const onAbort = () => { | |
| reject(new Error(signal.reason)); | |
| } | |
| signal.addEventListener('abort', onAbort); | |
| const cleanup = () => { | |
| signal.removeEventListener('abort', onAbort); | |
| } |
Not necessarily as a literal change, but more as the general direction
Comment on lines
+36
to
+38
| throw new TypeError( | ||
| `The "${name}" property must be an instance of AbortSignal.`, | ||
| ); |
Member
There was a problem hiding this comment.
Suggested change
| throw new TypeError( | |
| `The "${name}" property must be an instance of AbortSignal.`, | |
| ); | |
| const msg = `The "${name}" property must be an instance of AbortSignal` | |
| throw new TypeError(msg); |
| const invoke = async (method, args) => { | ||
| let signal = null; | ||
| let onAbort = null; | ||
| const lastArg = args[args.length - 1]; |
Member
There was a problem hiding this comment.
Suggested change
| const lastArg = args[args.length - 1]; | |
| const lastArg = args.at(-1); |
Comment on lines
+71
to
+73
| onAbort = () => { | ||
| reject(new Error(signal.reason)); | ||
| }; |
Member
There was a problem hiding this comment.
Suggested change
| onAbort = () => { | |
| reject(new Error(signal.reason)); | |
| }; | |
| onAbort = () => void reject(new Error(signal.reason)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
npm t)npm run fmt)Add support for thread-safe AbortContoller/Signal #41