different promise execution on browsers, what happened?

后端 未结 1 1902
眼角桃花
眼角桃花 2020-12-20 07:35
const b = () => {
  return new Promise(resolve => {
    resolve();
    Promise.resolve()
      .then(() => {
                 


        
相关标签:
1条回答
  • You have two completely independent promise chains here:

    Promise.resolve()
      .then(() => {
        console.log(1);
      })
      .then(() => console.log(3));
    
    
    (async () => {
      await new Promise(resolve => {
        resolve();
      });
      console.log(2);
    }());
    

    There is no guaranteed ordering other that 3 happens after 1. The rest is affected by how promise callbacks are queued exactly, and there was a change in the spec of await (omitting one unnecessary thenable resolution procedure) that is probably not yet implemented in the Safari engine.

    0 讨论(0)
提交回复
热议问题