I understand that 'go blocks' (whether go
or go-loop
or possibly other constructs) return a channel. However I have never understood this channel's purpose. I'd like to know how to use it. Perhaps I'm creating extra channels when I don't need to be.
相关问题
- Better Sequence Duplicate Remover
- Installation of Leiningen 2.X in Mac OS X
- Questions about Lists and other stuff in Clojure
- How do I add CORS to a compojure-api app?
- How do I use Clojure in Android Studio using Gracl
相关文章
- Factor Clojure code setting many different fields
- Does learning one Lisp help in learning the other?
- Better way to nest if-let in clojure
- Idiomatic approach for structuring Clojure source
- Is a “transparent” macrolet possible?
- Detect operating system in Clojure
- Using quote in Clojure
- Enums and Clojure
I use the return channel of a
go
-block as a handle that I can pass to another function (not just a macro) which wants to synchronize with the completion of thego
-block. Alternatively, I can preform blocking reads on the channel to guarantee when the execution of thego
-block has completed.Here is a simple example (not meant to be used for any production code to compute sum) that does a two-way parallelization:
In this example, we compute the left and right sums in parallel. Since we need the left sum to compute the overall sum, we have to wait on the result and retrieve the result of the
go
-block.