我是core.async的新手,我想知道为什么以下不起作用(根本没有输出):
(def jackie (chan 2))
(go (loop [food (<! jackie)]
(if food
(do
(println "Some" food "is what I was waiting for.")
(Thread/sleep 1000)
(recur (<! jackie))))))
(go (doseq [food ["carrots" "peas"]]
(println "deliver" food)
(>! jackie food)
(Thread/sleep 1000)))
......虽然这可行:
(def jackie (chan 2))
(go (loop [food (<! jackie)]
(if food
(do
(println "Some" food "is what I was waiting for.")
(Thread/sleep 1000)
(recur (<! jackie))))))
(doseq [food ["carrots" "peas"]]
(println "deliver" food)
(>!! jackie food)
(Thread/sleep 1000))
唯一的区别是上一个go
周围缺少doseq
块。
我在this blog post的示例中找到了合并的go
和doseq
,但它并不适用于我。另外,将go
嵌套在doseq
{{1}}内的{{1}}对我来说也不合适。
答案 0 :(得分:0)
>!!
将阻止当前线程。要改为使用当前的go block park,请使用单爆变种>!