JavaScript ES6 - Possible race condition between promise resolution and event?

Viewed 534

Is it possible to have user code executed between a promise resolution and a promise await return?

function a () {
  return new Promise(resolve => {
    setTimeout(() => {
      // Between here...
      resolve()
    }, 1000))
  }
}

async function b () {
  await a()
  // ...and here ?
}

Does the specification enforces that Promise callbacks are called immediatly? I wonder if an event could be handled by the virtual machine between the 2 points, possibly causing side-effects.

2 Answers
Related