This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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