Skip to content

Instantly share code, notes, and snippets.

@moea
Created August 14, 2015 18:50
Show Gist options
  • Save moea/cce33ab6898f724d9a2c to your computer and use it in GitHub Desktop.
Save moea/cce33ab6898f724d9a2c to your computer and use it in GitHub Desktop.
(defn decrement! [[from-str from-chan] [to-str to-chan] & [start-value]]
(go-loop [n (or start-value (<! from-chan))]
(println from-str "sends" n "to" to-str)
(>! to-chan n)
(when-let [reply (<! from-chan)]
(println from-str "gets" reply)
(if (pos? reply)
(recur (dec reply))
(do
(close! from-chan)
(close! to-chan)
(println "Finished"))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment