|
|
|
|
|
by joeycumines
963 days ago
|
|
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. |
|
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.