Last active
December 26, 2019 11:38
-
-
Save DavidVujic/e0374fa76c49d26cfbed9fffac0314d3 to your computer and use it in GitHub Desktop.
Node.js 12 blocking the event loop
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
function log(...args) { | |
console.log(Date.now().toString(), ...args); | |
} | |
function processData() { | |
log('processing ...'); | |
for (let i = 0; i < 1000000; i += 1) { | |
JSON.parse('{"hello": "world"}'); | |
} | |
return Promise.resolve(); | |
} | |
async function main() { | |
setTimeout(() => log('first timeout: done!')); | |
setTimeout(() => { | |
processData() | |
.then(processData) | |
.then(processData) | |
.then(processData); | |
}); | |
setTimeout(() => log('second timeout: done!')); | |
} | |
main() | |
.catch((err) => log(err.message)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment