Skip to content

setTimeouts are not dispatched in separate tasks #23773

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

Closed
aslushnikov opened this issue Oct 19, 2018 · 2 comments
Closed

setTimeouts are not dispatched in separate tasks #23773

aslushnikov opened this issue Oct 19, 2018 · 2 comments
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs.

Comments

@aslushnikov
Copy link
Contributor

The following reproduces for me on both node 8 and node 10.

let resolve;
const promise = new Promise(x => resolve = x);
promise.then(() => console.log('task1: promise resolved'));

setTimeout(() => {
  console.log('task1: settimeout');
  resolve();
}, 0);
setTimeout(() => console.log('task2: settimeout'), 0);

In Web, every setTimeout will be dispatched in a separate task; as a result, the script will always
yield:

task1: settimeout
task1: promise resolved
task2: settimeout

In node, however, the behavior is flaky and every other time I see the following:

task1: settimeout
task2: settimeout
task1: promise resolved

If this is intended behavior, I didn't find any description in documentation.

This, however, is very unexpected for someone coming from Web to Node.js.

@aslushnikov aslushnikov changed the title setTimeout should force a new task setTimeouts are not dispatched in separate tasks Oct 19, 2018
@mscdex
Copy link
Contributor

mscdex commented Oct 19, 2018

I believe this is a duplicate of #22257

@mscdex mscdex closed this as completed Oct 19, 2018
@mscdex mscdex added the duplicate Issues and PRs that are duplicates of other issues or PRs. label Oct 19, 2018
@aslushnikov
Copy link
Contributor Author

Awesome. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs.
Projects
None yet
Development

No branches or pull requests

2 participants