Re:Go-like channels in 10 lines of JavaScript
by eurasiantiger on Saturday February 04, 2023 @06:47PM
(#34659759)
No. All the JS code is still executing serially in the same event queue. This is a good thing, lean into the guarantees it provides.
[ Parent
| on HN ]
Re:Go-like channels in 10 lines of JavaScript
by vore on Saturday February 04, 2023 @07:24PM
(#34660090)
In 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.
Re:Go-like channels in 10 lines of JavaScript
by eurasiantiger on Sunday February 05, 2023 @03:23AM
(#34662994)
From experience, it is a strong enough guarantee to prevent many race conditions.
Re:Go-like channels in 10 lines of JavaScript
by jay-barronville on Saturday February 04, 2023 @06:54PM
(#34659831)
Sorry, 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.
Re:Go-like channels in 10 lines of JavaScript
by eurasiantiger on Sunday February 05, 2023 @03:21AM
(#34662990)
But those parallel executions are running their own event queues.