-
Notifications
You must be signed in to change notification settings - Fork 285
Open
Labels
bugSomething isn't workingSomething isn't working
Description
The following code executes promises first, then microtasks (queued with queueMicrotask) and then macrotasks (timeouts) on Chrome, Firefox and Safari.
setTimeout(() => console.lp("timeout #1 completed"), 0);
queueMicrotask(() => console.lp("microtask #1 completed"));
new Promise((resolve) => {
console.lp("promise #1 resolved");
resolve();
});
setTimeout(() => console.lp("timeout #2 completed"), 0);
new Promise((resolve) => {
console.lp("promise #2 resolved");
resolve();
});
queueMicrotask(() => console.lp("microtask #2 completed"));
queueMicrotask(() => console.lp("microtask #3 completed"));
setTimeout(() => console.lp("timeout #3 completed"), 0);Though promises are also microtasks, they're being given higher priority.
Since we're using the same queue for the timeouts and microtasks, timeouts may executed in-between microtasks:
WARN console : lightpanda . . . . . . . . . . . . . . . . . [+0ms]
args =
1: promise #1 resolved
WARN console : lightpanda . . . . . . . . . . . . . . . . . [+0ms]
args =
1: promise #2 resolved
WARN console : lightpanda . . . . . . . . . . . . . . . . . [+0ms]
args =
1: timeout #1 completed
WARN console : lightpanda . . . . . . . . . . . . . . . . . [+0ms]
args =
1: microtask #1 completed
WARN console : lightpanda . . . . . . . . . . . . . . . . . [+0ms]
args =
1: microtask #2 completed
WARN console : lightpanda . . . . . . . . . . . . . . . . . [+0ms]
args =
1: timeout #3 completed
WARN console : lightpanda . . . . . . . . . . . . . . . . . [+0ms]
args =
1: microtask #3 completed
WARN console : lightpanda . . . . . . . . . . . . . . . . . [+0ms]
args =
1: timeout #2 completed
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working