3 ms·
I'll take a stab: In JavaScript, you only have one thread. You really don't want to block it for any length of time. IO tends to take time. So IO is always asy
by patrickthebold 5y ago
I'll take a stab:
In JavaScript, you only have one thread. You really don't want to block it for any length of time. IO tends to take time. So IO is always async. There's no way to turn something async into something synchronous without blocking your thread waiting.
Other languages do let you block a thread to wait for an async task to complete, JavaScript doesn't mostly because there is only one thread.
- endorphine 5y agoI see, so the asynchronous model that JavaScript implements is an answer to the question: > Given a single thread, how can we do multiple things at once (slow I/O, process user events like a mouse click etc.) And the answer to this, is that we use continuations. Is that correct?
- patrickthebold 5y agoYep, and even in languages with multiple (OS) threads, a thread is still a resource with a stack that takes some memory, and so they might also do non-blocking IO with either with callbacks or promises or similar.