This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-03
Channels
- # announcements (8)
- # aws (2)
- # babashka (16)
- # beginners (173)
- # calva (13)
- # cider (4)
- # cljfx (6)
- # cljs-dev (108)
- # clojure (63)
- # clojure-australia (2)
- # clojure-dev (10)
- # clojure-europe (73)
- # clojure-italy (8)
- # clojure-nl (4)
- # clojure-norway (5)
- # clojure-uk (4)
- # clojurescript (49)
- # clojureverse-ops (4)
- # community-development (3)
- # core-async (23)
- # cursive (3)
- # data-science (5)
- # datomic (25)
- # emacs (3)
- # events (1)
- # fulcro (13)
- # helix (5)
- # introduce-yourself (1)
- # lein-figwheel (1)
- # lsp (36)
- # malli (1)
- # meander (2)
- # membrane (4)
- # music (8)
- # nextjournal (51)
- # off-topic (47)
- # other-languages (5)
- # pathom (31)
- # pedestal (5)
- # planck (14)
- # polylith (5)
- # portal (1)
- # re-frame (30)
- # react (2)
- # reagent (24)
- # releases (1)
- # rewrite-clj (18)
- # ring (9)
- # sci (33)
- # shadow-cljs (49)
- # testing (3)
- # tools-build (21)
- # tools-deps (29)
- # vim (19)
- # web-security (1)
- # xtdb (12)
good morning. i have a how-to question regarding mult, tap, and the various pipelines.
;; Goal:
;; + messages published on channel out-1.
;; + messages should be sent to both in-1 and in-2.
;; + messages for in-1 and in-2 should travel different
;; processing paths.
;; create all 3 base channels.
(def out-1 (a/chan 5))
(def in-1 (a/chan 5))
(def in-2 (a/chan 5))
;; create a mult of out-1, and tap this multi to both
;; in-1 and in-2.
(def out-1-mult (a/mult out-1))
(a/tap out-1-mult in-1)
(a/tap out-1-mult in-2)
;; transducer stack to apply on the pipeline. Take a
;; number, add n, then multiply by 2.
(defn xform
[n]
(comp
(map #(+ n %))
(map #(* 2 %))))
;; The pipeline between out-1 (out-1-mult) and in-1 should
;; run the transducer stack with parameter 1.
(def p-1 (a/pipeline
1
in-1
(xform 1)
out-1-mult))
(def p-2 (a/pipeline
1
in-2
(xform 2)
out-1-mult))
(a/>!! out-1 1)
(a/<!! in-1)
(a/<!! in-2)
this results in the following exception:
Exception in thread "async-dispatch-2" java.lang.IllegalArgumentException: No implementation of method: :take! of protocol: #'clojure.core.async.impl.protocols/ReadPort found for class: clojure.core.async$mult$reify__14980
is there guidance on higher level channel abstractions and pipelines?
that makes sense
but i can use out-1
perfect
it looks like it eludes the pipeline effect, though
(a/>!! out-1 1)
(a/<!! in-1) => 1
(a/<!! in-2) => 1
in this case, ill be expected to use in-1 and in-2 as the from parameter, and spin up another pair of in channels
user=> (doc a/pipeline)
-------------------------
clojure.core.async/pipeline
([n to xf from] [n to xf from close?] [n to xf from close? ex-handler])
your arguments look backwardsi want the message to flow from the out-1 -> in-1|in-2
this works:
;; Goal:
;; + messages published on channel out-1.
;; + messages should be sent to both in-1 and in-2.
;; + messages for in-1 and in-2 should travel different
;; processing paths.
;; create all 3 base channels.
(def out-1 (a/chan 5))
(def in-1 (a/chan 5))
(def in-2 (a/chan 5))
;; create a mult of out-1, and tap this multi to both
;; in-1 and in-2.
(def out-1-mult (a/mult out-1))
(a/tap out-1-mult in-1)
(a/tap out-1-mult in-2)
;; in-1 and in-2 now become source channels for the
;; proceeding pipelines.
(def in-1-final (a/chan 5))
(def in-2-final (a/chan 5))
;; transducer stack to apply on the pipeline. Take a
;; number, add n, then multiply by 2.
(defn xform
[n]
(comp
(map #(+ n %))
(map #(* 2 %))))
;; The pipeline between out-1 (out-1-mult) and in-1 should
;; run the transducer stack with parameter 1.
(def p-1 (a/pipeline
1
in-1-final
(xform 1)
in-1))
(def p-2 (a/pipeline
1
in-2-final
(xform 2)
in-2))
(a/>!! out-1 1)
(a/<!! in-1-final)
(a/<!! in-2-final)
the last 2 reads produce 4 and 6 respectively
the multi + tap actions turn the in-1 and in-2 into the <from> args of the pipeline
effectively broadcast + pipeline i guess