Search code examples
clojureclojurescriptcore.async

What transformation is go macro doing to the user’s code?


How go macro transforms the code

(let [c1 (chan)
      c2 (chan)]
  (go (while true
        (let [[v ch] (alts! [c1 c2])]
          (println "Read" v "from" ch))))
  (go (>! c1 "hi"))
  (go (>! c2 "there")))

Solution

  • It is a state machine at the back. You can read more in The State Machines of core.async