Skip to content

Add support for AbortSignal in methods#42

Open
Lily0603 wants to merge 4 commits into
metarhia:mainfrom
Lily0603:signal
Open

Add support for AbortSignal in methods#42
Lily0603 wants to merge 4 commits into
metarhia:mainfrom
Lily0603:signal

Conversation

@Lily0603

@Lily0603 Lily0603 commented Feb 9, 2026

Copy link
Copy Markdown

Comment thread noroutine.js Outdated
Comment on lines +70 to +72
signal.addEventListener('abort', () => {
reject(new Error(signal.reason));
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 thread noroutine.js Outdated
Comment on lines +36 to +38
throw new TypeError(
`The "${name}" property must be an instance of AbortSignal.`,
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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);

Comment thread noroutine.js Outdated
const invoke = async (method, args) => {
let signal = null;
let onAbort = null;
const lastArg = args[args.length - 1];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
const lastArg = args[args.length - 1];
const lastArg = args.at(-1);

Comment thread noroutine.js Outdated
Comment on lines +71 to +73
onAbort = () => {
reject(new Error(signal.reason));
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
onAbort = () => {
reject(new Error(signal.reason));
};
onAbort = () => void reject(new Error(signal.reason));

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