Skip to content

Instantly share code, notes, and snippets.

@DavidVujic DavidVujic/processData.js
Last active Dec 26, 2019

Embed
What would you like to do?
Node.js 12 blocking the event loop
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
You can’t perform that action at this time.