Event loop blocking limits during CPU-intensive go-blocks
0 reputation · 08 Oct 2021, 02:48 UTC
ClojureScript relies on the single-threaded event loop of the JavaScript host environment. While core.async provides go-blocks to manage asynchronous flows via state machines, these blocks are designed to yield during channel operations rather than preempting long-running synchronous computations.
When a go-block contains a heavy CPU-bound task—such as a complex data transformation or a large loop—without an intervening or channel operation, the execution remains synchronous on the main thread. This behavior introduces latency for all other concurrent requests or UI events until the computation completes.
Given these execution constraints, what are the established patterns for ensuring a long-running synchronous process within a go-block does not starve the event loop? Is there a documented mechanism to force a yield to the host environment without manually inserting channel-based delays?