go
and thread
will return a channel with buffer-size of zero containing the result of the body. That's exploited in the following snippet from the core.async walkthrough, which more or less "tests" (assert
s) that the value "hello"
is successfully communicated over the channel c
.
(let [c (chan)]
(go (>! c "hello"))
(assert (= "hello" (<!! (go (<! c)))))
(async/close! c))
Note that the assert is neither within the go
block nor directly outside go
, because as outlined above, the result will be another channel. So the assertion checks the result of the blocking take !<<
on the result channel. This is a useful pattern for testing core.async code: return the result channel from your taking code and run the test with a blocking take on it, like this: