I recently enjoyed watching the Google IO talk on Go Concurrency patterns
Although the Go approach to concurrency (groutines, communication over channels) is clearly different to Clojure (immutability, manged references, STM), it seemed like the Go approach could still be useful in some circumstances in a Clojure context.
So is there a direct equivalent in Clojure or Java for Go's concurrency primitives (perhaps a library), in particular:
channel
-like objects that block until a reader and writer are available at both endsselect
-like construct that can wait for results on multiple channelsP.S. Perfectly happy with a Java solution since it would be easy to use from Clojure
UPDATE Since the question was originally asked, Clojure now has core.async which provides all this functionality and more.
Goroutine is a lightweight thread in Golang. All programs executed by Golang run on the Goroutine. That is, the main function is also executed on the Goroutine. In other words, every program in Golang must have a least one Goroutine.
Threads are hardware dependent. Goroutines have easy communication medium known as channel. Thread does not have easy communication medium. Due to the presence of channel one goroutine can communicate with other goroutine with low latency.
A goroutine is a lightweight thread managed by the Go runtime.
A goroutine is a lightweight execution thread in the Go programming language and a function that executes concurrently with the rest of the program. Goroutines are incredibly cheap when compared to traditional threads as the overhead of creating a goroutine is very low.
You should check out core.async. It is a library written by Rich Hickey that implements go style channels.
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