We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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.
The text was updated successfully, but these errors were encountered:
From https://nodejs.org/api/timers.html#timers_settimeout_callback_delay_args:
Node.js makes no guarantees about the exact timing of when callbacks will fire, nor of their ordering.
Sorry, something went wrong.
See also #15081
Answered, closing.
No branches or pull requests
Here are some code.
When i execute it in Node, i got result like this:
But when i execute it in browser(MAC OS chrome 62.0.3202.94), i got result like this:
I am puzzled by the result of this implementation.
The text was updated successfully, but these errors were encountered: