3 ms·
> But there is no concurrency in Javascript! Yes and no. At the “ECMAScript”-level, JavaScript has no built-in concurrency, but every serious JavaScript imple
by jay-barronville 4y ago
> But there is no concurrency in Javascript!
Yes and no.
At the “ECMAScript”-level, JavaScript has no built-in concurrency, but every serious JavaScript implementation enables proper concurrency via the async primitives and the internal scheduling.
Put simply, if you know how to write async code properly, your JavaScript code can achieve high concurrency!
- eurasiantiger 4y agoNo. All the JS code is still executing serially in the same event queue. This is a good thing, lean into the guarantees it provides.
- jay-barronville 4y agoSorry, I think you’re misunderstanding. Highly concurrent code need not execute in parallel. Concurrency enables parallelism; concurrency does NOT mandate parallelism. On top of that, it actually is possible in JavaScript environments like Node.js to write code that can, in fact, run in parallel.
- eurasiantiger 4y agoBut those parallel executions are running their own event queues.
- vore 4y agoIn an async function, the only guarantee you have is that code between two await points is not interruptible. As you have more and more async operations, this guarantee gets pretty weak (if you have more than one pending async task and the current task yields, which one will run next?) and you have to start employing the usual locking mechanisms to ensure correctness.
- eurasiantiger 4y agoFrom experience, it is a strong enough guarantee to prevent many race conditions.