放置然后立即从通道中删除值会导致奇怪的行为(ClojureScript core.async)

Putting then immediately removing value from channel causes weird behavior (ClojureScript core.async)

以下是出于学习目的而设计的示例。它涉及将值 "val" 塞入通道,然后立即在 go 块中将其删除:

(def test-chan1 (chan))

(go 
  (println 
    (<! 
      (go 
        (do 
          (>! test-chan1 "val") 
          (<! test-chan1)))))) ; the return value of the (do..) is "val" 
                               ; ...hence the return value of the nested go block should be a channel containing "val"
                               ; hence (println ..) should eventually print "val" to the console

问题:为什么这个代码片段不打印"val"到控制台?

默认情况下通道是同步的,因此 put 将阻塞直到有人要 get(反之亦然)。

所以你的问题是内部 go 永远被阻塞在 put (>!) 上。尝试将您的频道更改为 (channel 1).