Created
May 12, 2020 07:09
-
-
Save lymanlai/93fb29c983f7020ff6bd82fbff8a7b4e to your computer and use it in GitHub Desktop.
event loop stuff
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
console.log('1, time = ' + new Date().toString()) | |
setTimeout(macroCallback, 0); | |
new Promise(function (resolve, reject) { | |
console.log('2, time = ' + new Date().toString()) | |
resolve(); | |
console.log('3, time = ' + new Date().toString()) | |
new Promise((rs1) => { | |
console.log('rs1') | |
rs1(); | |
}).then(() => { | |
console.log('rs1 cb') | |
new Promise((rs2) => { | |
console.log('rs2') | |
rs2(); | |
new Promise((rs3) => { | |
console.log('rs3') | |
rs3(); | |
}).then(() => { | |
console.log('rs3 cb') | |
}) | |
}).then(() => { | |
console.log('rs2 cb') | |
}) | |
}) | |
}).then(microCallback); | |
function macroCallback() { | |
console.log('4, time = ' + new Date().toString()) | |
} | |
function microCallback() { | |
console.log('5, time = ' + new Date().toString()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment