Last active
July 11, 2021 15:45
-
-
Save Goloburda/b6e2ec38052e417605a2acc08ad78c7c to your computer and use it in GitHub Desktop.
Micro/Macro tasks
This file contains 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
// https://www.youtube.com/watch?v=cCOL7MC4Pl0 | |
const button = document.getElementsByTagName('button')[0] | |
button.addEventListener('click', () => { | |
setTimeout(() => console.log('Timeout 1')) | |
Promise.resolve().then(() => console.log('Microtask - 1')) | |
console.log('task 1') | |
}) | |
button.addEventListener('click', () => { | |
setTimeout(() => console.log('Timeout 2')) | |
Promise.resolve().then(() => console.log('Microtask - 2')) | |
console.log('task 2') | |
}) | |
/* | |
"task 1" | |
"Microtask - 1" | |
"task 2" | |
"Microtask - 2" | |
"Timeout 1" | |
"Timeout 2" | |
*/ | |
// button.click() | |
/* | |
"task 1" | |
"task 2" | |
"Microtask - 1" | |
"Microtask - 2" | |
"Timeout 1" | |
"Timeout 2" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment