0
votes

The following is a contrived example for learning purposes. It involves jamming the value "val" into a channel and then immediately removing it within a go block:

(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

Question: Why does this code snippet not print "val" to the console?

1
Minor comment, you dont need the 'do' - DanLebrero

1 Answers

3
votes

Channels by default are synchronous, so a put will block until there is somebody to get (and the other way around).

So Your problem is that the inner go is blocked on the put (>!) forever. Try changing your channel to (channel 1).