Skip to content

Instantly share code, notes, and snippets.

@patrickhulce
Created February 8, 2022 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickhulce/0c4c7b6b05937b6854b048a20b7ddb6c to your computer and use it in GitHub Desktop.
Save patrickhulce/0c4c7b6b05937b6854b048a20b7ddb6c to your computer and use it in GitHub Desktop.
Microtask flush example
let x = 0;
new Promise(resolve => resolve()).then(() => {
x = 1
new Promise(resolve => resolve()).then(() => {
x = 2
})
})
await flushAllMicrotasks()
console.log(x) // This will print `2` instead of `0`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment