Skip to content

Instantly share code, notes, and snippets.

@peterschwarz
Created April 16, 2014 23:32
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 peterschwarz/10942328 to your computer and use it in GitHub Desktop.
Save peterschwarz/10942328 to your computer and use it in GitHub Desktop.
Core.async `mult` example
(require '[clojure.core.async :refer [chan timeout >!! <!! alts!! mult tap]])
(defn td [ch]
(first (alts!! [ch (timeout 100)])))
(def c (chan 10))
(>!! c :foo) ; true
(>!! c :bar) ; true
(td c) ; :foo
(td c) ; :bar
(def m (mult c))
(>!! c :after) ; true
(>!! c :again) ; true
(td c) ; nil
(def t (chan 10))
(tap m t)
(>!! c :more) ; true
(td c) ; nil
(td t) ; :more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment