Clojure - Why does execution hang when doing blocking insert into channel? (core.async)

前端 未结 2 785
梦如初夏
梦如初夏 2021-01-04 23:24

Consider the following snippet:

(let [chs (repeatedly 10 chan)]
  (doseq [c chs]
    (>!! c \"hello\"))
  (doseq [c chs]
    (println (

        
2条回答
  •  逝去的感伤
    2021-01-04 23:35

    That channel has no buffer, and >!! is blocking. Refer to the examples for this exact case. They spawn a second thread for this reason - to prevent blocking the main thread. Using a goroutine, as in your question, operates on a similar principle.

    You can also create the channel with some buffer space - (chan 1)

提交回复
热议问题