core.async中的doseq go宏不起作用

时间:2014-12-23 11:11:24

标签: asynchronous clojure core.async

我是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的示例中找到了合并的godoseq,但它并不适用于我。另外,将go嵌套在doseq {{1}}内的{{1}}对我来说也不合适。

1 个答案:

答案 0 :(得分:0)

如果目标通道/缓冲区已满,

>!!将阻止当前线程。要改为使用当前的go block park,请使用单爆变种>!