Skip to content

Instantly share code, notes, and snippets.

@shaunxcode
Created October 29, 2015 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunxcode/4f49eb4184fffc250742 to your computer and use it in GitHub Desktop.
Save shaunxcode/4f49eb4184fffc250742 to your computer and use it in GitHub Desktop.
(require '[clojure.core.async :as ca])
(def some-ch (ca/chan))
(def result-ch (ca/reduce
(fn [xs msg]
(if (= msg :done)
(reduced xs)
(conj xs msg)))
[]
some-ch))
(ca/put! some-ch :a)
(ca/put! some-ch :b)
(ca/put! some-ch :done)
(ca/<!! result-ch) ;;[:a :b]
(ca/put! some-ch :c)
(ca/<!! some-ch) ;; :c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment