3 ms·
> Yes blocking the event loop is easy. No it's not THAT easy. I've never done it because you think about it while writing code. To be pedantic, all JavaScript
by Osiris 7y ago
> Yes blocking the event loop is easy. No it's not THAT easy. I've never done it because you think about it while writing code.
To be pedantic, all JavaScript functions block the event loop. It's just that the vast majority of functions execute so quickly that the amount of time your function blocks is very short.
I once had a loop that processed tons of data and would block the event loop for 1-3 seconds. I ended up solving it by writing an asynchronous loop which used promises and process.nextTick() to make each iteration a separate execution block on the event loop. But I've only had to do something weird like that once in 10 years of node development.
- winrid 7y agoRight sorry. I meant for a significant amount of time that took down production or caused serious issues. I've taken down prod in other ways though :p At one company I built API middleware that calculated time spent in the event loop vs waiting on dependencies (other apis, Redis, etc) by managing a couple counters per request. It was very helpful.