I'm new to core.async (and CSP more generally) and struggling to find good debugging strategies. In particular, I frequently fail to diagnosis which part of the code is infinitely blocking the main thread. I'll give a particular example:
(deftest passing-test
(let [c (async/to-chan! [2 1 0 5 4])]
(is (= [2 1 0 5 4]
(async/<!! (async/into [] c))))))
(deftest hanging-test
(let [[e o] (->> (async/to-chan! [2 1 0 5 4])
(async/split even?))]
(is (= [2 0 4]
(async/<!! (async/into [] e))))
(is (= [1 5]
(async/<!! (async/into [] o))))))
The first test passes and does not block the main thread. The second test hangs forever. The only difference is the addition of async/split
to route even and odd integers to their respective channels.
My specific questions are as follows:
What explains the difference between the first and second tests with respect to blocking the main thread?
What are some strategies to debugging core.async code that is unexpectedly blocking the main thread?
What is the best way to write unit tests for code that creates and manipulates channels? Is (async/<!! (async/into [] o))
a reasonable way to collect the values flowing through a channel into a collection?