-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
The order of Task & MicroTask execution is inconsistent with browser #17181
Copy link
Copy link
Closed
Labels
promisesIssues and PRs related to ECMAScript promises.Issues and PRs related to ECMAScript promises.questionIssues that look for answers.Issues that look for answers.
Description
- Version: 8.1.3
- Platform: Mac OS
- Subsystem: 10.12.4
Here are some code.
function func1(i){
return new Promise((resolve,reject)=>{
setTimeout(()=>{
console.log("func1: ",i)
resolve(true)
},1000)
})
}
async function func2(i){
await func1(i)
console.log("func2:",i)
}
function test(){
for(var i=0; i<5; i++){
func2(i)
console.log("loop:",i)
}
}
test();
When i execute it in Node, i got result like this:
loop: 0
loop: 1
loop: 2
loop: 3
loop: 4
func1: 0
func2: 0
func1: 1
func1: 2
func1: 3
func1: 4
func2: 1
func2: 2
func2: 3
func2: 4
But when i execute it in browser(MAC OS chrome 62.0.3202.94), i got result like this:
loop: 0
loop: 1
loop: 2
loop: 3
loop: 4
func1: 0
func2: 0
func1: 1
func2: 1
func1: 2
func2: 2
func1: 3
func2: 3
func1: 4
func2: 4
I am puzzled by the result of this implementation.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
promisesIssues and PRs related to ECMAScript promises.Issues and PRs related to ECMAScript promises.questionIssues that look for answers.Issues that look for answers.