Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ...
by olalonde on Monday November 06, 2023 @10:05AM
(#38163562)
IME, race conditions are pretty easy to solve in JS, because the flow of code execution is only susceptible to be interrupted at known locations (async function calls). Here's an example of how you could solve the problem you mentioned in a few lines of JavaScript:
Although it's probably best to just use one of the queue libraries on npm. This one for example: https://www.npmjs.com/package/p-queue
[ Parent
| on HN ]
Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ...
by joeycumines on Monday November 06, 2023 @04:00PM
(#38168938)
Hey, that's a neat little trick to implement locking in JS, thanks.
I oversimplified my example perhaps - it also involved handling interruptions (certain system events), maintaining a lifecycle (set up and tear down), and scenarios where it allowed a certain subset of operations to be performed, while performing one of several operations. That last requirement was due to it using shell scripts to perform configuration of the system, and it needing to extract runtime and configuration information from the main daemon.
Still though, thanks very much for your comments, I've enjoyed reading them.