Skip to content

Instantly share code, notes, and snippets.

@patrickhulce
Created February 8, 2022 21:18
Show Gist options
  • Select an option

  • Save patrickhulce/0c4c7b6b05937b6854b048a20b7ddb6c to your computer and use it in GitHub Desktop.

Select an option

Save patrickhulce/0c4c7b6b05937b6854b048a20b7ddb6c to your computer and use it in GitHub Desktop.

Revisions

  1. patrickhulce created this gist Feb 8, 2022.
    11 changes: 11 additions & 0 deletions microtasks.mjs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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`.