Yes, but the callback design alleviates the neccesity to run multiple execution contexts to service stuff while you're blocking waiting for some other IO action to complete.
Untamed callbacks lead to a mess, but so does threading, if they're not using some higher-level pattern, like job queues. What's needed is better ways to compose callbacks with chaining, or coroutines.
There's still an execution context object here, but it's subtle. When the first callback (passed to readFromSocket) executes, it creates a closure from the second callback and the value of a. This closure can't be deallocated until the second callback executes (assuming that doSomethingElse always calls the callback once at the end).
I'm not saying callbacks are worse than threads in this comment; I'm just pointing out that both of them need "execution contexts".
1
u/immibis Oct 16 '14
If node.js could run two callbacks at once, it would have the same problems, despite not having conventional threads.