【发布时间】:2016-08-28 21:05:15
【问题描述】:
我已经使用 core.async thread 函数创建了这个生产者/消费者模式,如下所示:
(defn -db-producer-factory [order-ids-chan next-chan]
(thread
(while true
(do
(let [order-id (<!! order-ids-chan)]
(condp = order-id
:finished (do
(>!! next-chan :finished))
(supress-w-nextexc
(->>
; get denorm'd order
(-> (r/-get-order :live order-id)
denorm/order->denormalized)
; put in a map to avoid nils
(hash-map :data)
(>!! next-chan)))))))))
但是,当我阅读 the documentation 的 thread 时,它说:
在另一个线程中执行主体,立即返回到 调用线程。返回将接收结果的通道 完成后的正文。
听起来它期望线程被一次性调用;并不是说它是为其中的while 循环而构建的。
我不应该在thread 块中执行while true 吗?或者当我关闭thread的结果chan时线程会被清理吗?
【问题讨论】:
标签: multithreading clojure core.async