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
Feature: Abort controller support #527
Comments
What about kill() method? It already works. |
yes, that's worked, but the reason is resources. When signal comes for promises, it's not stops actually. and resources are not flushed. I mean what's happens when do the snippet: function delay(ms: number){
return new Promise(res => setTimeout(res, ms)})
}
await Promise.race([
delay(1000),
asyncFnLessThan1000ms(),
]) set timeout will not stops actually, results will be ignored (it takes machine time) But if we use the signal to stop any async code( The same behavior for the child process, This feature will reduce process memory/time management |
Native intertop with signal would make the API a lot nicer to use. Now the API feels awkward: handle: async ({ signal }) => {
const promise = $`sleep 30`;
const kill = () => {
promise.kill();
};
signal.addEventListener('abort', kill, { once: true });
await promise;
signal.removeEventListener('abort', kill);
}, If handle: async ({ signal }) => {
await $({signal})`sleep 30`;
}, This API is similar to how |
Please show an example with usage with signal vs kill() |
Updated |
As a part of node.js 16. Abort signal stable feature. I would like to propose Abort signal and Abort Controller support.
API:
The text was updated successfully, but these errors were encountered: