Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.3k
Closed
Labels
promisesIssues and PRs related to ECMAScript promises.Issues and PRs related to ECMAScript promises.timersIssues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
Description
- Version: 8.4.0
- Platform: Windows 7 x64
- Subsystem: libuv, promises
Revisiting this article, I've found out that an example which illustrates some known bug (?) in microtask queue execution behaves differently because of times of script call.
'use strict';console.log('script start')constinterval=setInterval(()=>{console.log('setInterval')},0)setTimeout(()=>{console.log('setTimeout 1')Promise.resolve().then(()=>{console.log('promise 3')}).then(()=>{console.log('promise 4')}).then(()=>{setTimeout(()=>{console.log('setTimeout 2')//< place of random microtask queue intrusionPromise.resolve().then(()=>{console.log('promise 5')}).then(()=>{console.log('promise 6')}).then(()=>{clearInterval(interval)})},0)})},0)Promise.resolve().then(()=>{console.log('promise 1')}).then(()=>{console.log('promise 2')})Every first call in a new cmd.exe terminal produces the mentioned error. Every next call has proper execution order:
>node test.jsscript startpromise 1promise 2setIntervalsetTimeout 1promise 3promise 4setIntervalsetTimeout 2setInterval //< intruderpromise 5promise 6>node test.jsscript startpromise 1promise 2setIntervalsetTimeout 1promise 3promise 4setIntervalsetTimeout 2promise 5promise 6Compare the next step after the setTimeout 2 output.
benjamingr
Metadata
Metadata
Assignees
Labels
promisesIssues and PRs related to ECMAScript promises.Issues and PRs related to ECMAScript promises.timersIssues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.