Created
February 8, 2022 21:18
-
-
Save patrickhulce/0c4c7b6b05937b6854b048a20b7ddb6c to your computer and use it in GitHub Desktop.
Microtask flush example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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