Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created June 22, 2017 14:56
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 swannodette/dee03ccb778f53fa1564e553bfd080d5 to your computer and use it in GitHub Desktop.
Save swannodette/dee03ccb778f53fa1564e553bfd080d5 to your computer and use it in GitHub Desktop.
(ns async-test.core
(:require-macros [cljs.core.async.macros :as async])
(:require [cljs.core.async :as async]))
(enable-console-print!)
(defn looper [ch handler-fn]
(async/go-loop []
(handler-fn (async/<! ch))
(recur)))
(defn run []
(let [bus (async/chan)
t-pub (async/pub bus :topic1)
sub1-ch (async/chan)
sub2-ch (async/chan)]
(async/sub t-pub :evt1 sub1-ch)
(looper sub1-ch (fn [v] (print "-")))
(async/sub t-pub :evt2 sub2-ch)
(looper sub2-ch (fn [v] (print "+")))
(dotimes [i 80]
(async/put! bus {:topic1 :evt1 :payload "foo"})
(async/timeout 100)
(async/put! bus {:topic1 :evt2 :payload "bar"}))))
(run)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment