Skip to content

Instantly share code, notes, and snippets.

@otarim
Created February 15, 2019 03:54
Show Gist options
  • Select an option

  • Save otarim/1634fa1994f12b15438e25112b27c75a to your computer and use it in GitHub Desktop.

Select an option

Save otarim/1634fa1994f12b15438e25112b27c75a to your computer and use it in GitHub Desktop.
microtask,macrotask
async function a() {
await f()
console.log('a')
}
async function f() {
console.log('f')
}
a()
new Promise((resolve, reject) => {
console.log('p')
resolve()
}).then(re => console.log('p1'))
new Promise((resolve, reject) => {
console.log('_p')
resolve()
}).then(re => console.log('p2'))
// f p _p a p1 p2
(async function() {
await a()
new Promise((resolve, reject) => {
console.log('p')
resolve()
}).then(re => console.log('p1'))
new Promise((resolve, reject) => {
console.log('_p')
resolve()
}).then(re => console.log('p2'))
})()
// f a p _p p1 p2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment