Skip to content

Instantly share code, notes, and snippets.

@jlongster
Last active August 29, 2015 14:05
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 jlongster/412d4616d3042288ea90 to your computer and use it in GitHub Desktop.
Save jlongster/412d4616d3042288ea90 to your computer and use it in GitHub Desktop.
(ns csp.core
(:require [clojure.core.async :as async
:refer [chan go >! <! <!! timeout pub sub]])
(:require [clojure.pprint :refer [pprint]])
(:gen-class))
(def c (chan))
(def p (pub c (fn [[tag & _]] tag)))
(def c1 (sub p :baz (chan)))
(def c2 (sub p :baz (chan)))
(def c3 (sub p :baz (chan)))
(defn -main [& args]
(go
(let [v (<! c1)]
(println "c1" v)))
(go
(let [v (<! c2)]
(println "c2" v)))
(go
(println "waiting...")
(<! (async/merge [c1]))
(let [v (<! c3)]
(println "c3" v)))
(println "starting")
(go
(>! c [:baz 1 2 3]))
(<!! (go (<! (timeout 10000)))))
@jlongster
Copy link
Author

Output:

% lein run
starting
waiting...
c2 c1 [[:baz :baz 1 2 13 ]2 
3]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment