Is it possible to use ClojureScript's state machine-based implementation of core.async in Clojure, rather than Clojure's thread-based implementation? I'd like to be able to use core.async on the JVM but without using threads.
There is no way to use core.async on the JVM in a strictly single-threaded fashion, unless you're willing to reach into the internals and replace the threadpool used for go
s with one that only uses a single thread.
However, as edbond points out in his comment, the Clojure version of core.async does use state machines for handling go
s. These state machines are then run on threads from a thread pool whose size is limited to double the number of processors + 42, so it is possible to launch thousands of go
s without using as many real threads.
The JVM core.async also provides a thread
macro that works like go
, but launches real threads, plus a collection of double-bang operations (<!!
, >!!
etc.) that work like their single-bang counterparts, but in a blocking fashion. Whether you use them is up to you; if you stick to go
and the single-bang family of operations, core.async will never launch any threads beyond the above-mentioned threadpool limit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With