Hacker News new | ask | show | jobs
by kazagistar 3414 days ago
Anything that suspends processing and waits for the OS to provide some data (file, time, socket, or piping usually) should be behind a callback. Beyond that benefit is more limited (in a single threaded app like NodeJS), since you are no longer using async to do othe stuff while you wait for resources. However, if the computation locks up the thread for too long, it cannot service callbacks, and so timers might be delayed, heartbeat messages might be skipped leading to dropped connections, and other bad stuff. If that's the case you want to either split your large computation into many smaller ones (allowing other callbacks to fire in between) or offload the computation into another process or thread.

In other words, it's an engineering decision, based on the expected consequences of the overall design in the context of understanding how the event reactor works.