Goroutines in PureScript
A goroutine is a lightweight thread of execution.
Suppose we have a function call f("s")
. Here’s how we’d call that in the usual way, running it synchronously.
To invoke this function concurrently as in goroutine, we use launchAff_
from the Effect.Aff
module to execute it asynchronously.
You can also start a concurrent execution for an anonymous function call.
Our two function calls are running asynchronously in separate contexts now. Wait for them to finish by adding appropriate delays or using more robust approaches like using promises or callbacks.
When we run this program, we see the output of the blocking call first, then the output of the two async calls. The async calls’ output may be interleaved, because they are being run concurrently.