News for hackers. Stuff that matters.
Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by joeycumines on Sunday November 05, 2023 @11:11PM (#38158753)
The concurrency comes from providing mechanisms to communicate between independent, asynchronous chains of operations.

Here is an example, that I based on an example from within the Go spec: https://github.com/joeycumines/ts-chan/blob/main/examples/co...

Here is the same example in Go: https://github.com/joeycumines/ts-chan/blob/main/examples/co...

The JS example is, obviously, much slower, and is fairly contrived - I wouldn't expect anyone to actually want to do that, specifically. The JS one is more complicated primarily because I used it in a benchmark, so needed a mechanism to stop the concurrent, asynchronous chains of operations, once it reached the target number of primes.

I hope that explains it for you.

Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by yunohn on Monday November 06, 2023 @05:43AM (#38160939)
Excuse my multiple comments, just trying to understand this better since I’m very intrigued by your library.

What does the JS “if x != x” check do? I don’t see the equivalent in the golang example?

Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by joeycumines on Monday November 06, 2023 @06:41AM (#38161266)
From the concurrent prime sieve example?

That's just something I copy and pasted from the documentation for the benchmark package I used. Allegedly, it is to prevent "certain compiler optimisations", which is something I'm familiar with when it comes to benchmarking Go code, for example.

I lack specific knowledge as to whether it's actually necessary, sorry :)

Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by yunohn on Tuesday November 07, 2023 @12:37AM (#38173642)
Ah, gotcha!

I thought maybe it was something to do with concurrency, and somehow x is affected by a race condition there.

Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by 29athrowaway on Monday November 06, 2023 @08:22PM (#38171854)
It is not what is widely understood as concurrency and the documentation for Promise type is clear in that regard.

Nothing happens concurrently (at the same time), only asynchronously (at different times).

From the documentation:

> Note that JavaScript is single-threaded by nature, so at a given instant, only one task will be executing, although control can shift between different promises, making execution of the promises appear concurrent. Parallel execution in JavaScript can only be achieved through worker threads.

I hope that explains it for you.

Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by joeycumines on Tuesday November 07, 2023 @05:05PM (#38183622)
Concurrency != Parallel execution
Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by 29athrowaway on Tuesday November 07, 2023 @11:40PM (#38186874)
In JS, without worker threads or similar situations, you don't have real race conditions. Therefore, concurrency primitives like mutexes, condition variables, barriers, semaphores, etc. are not necessary.

You can use a global variable and it will be fine because it won't be accessed simultaneously.

So truly what this is is https://www.youtube.com/watch?v=aYSSYm0b2wk

Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by joeycumines on Wednesday November 08, 2023 @05:44AM (#38188710)
What makes data races not a "real race condition"?

Anyhow, do what you will. I don't get the impression that you are genuinely interested in this topic.

Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by 29athrowaway on Wednesday November 08, 2023 @05:50PM (#38198376)
Thanks for conceding the point. Have fun.