This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-01
Channels
- # announcements (10)
- # aws (1)
- # babashka (19)
- # beginners (104)
- # calva (50)
- # cider (17)
- # cljs-dev (135)
- # cljsrn (56)
- # clojure (240)
- # clojure-dev (4)
- # clojure-europe (19)
- # clojure-nl (2)
- # clojure-uk (7)
- # clojurescript (22)
- # conjure (2)
- # css (1)
- # cursive (10)
- # data-science (1)
- # datomic (60)
- # emacs (2)
- # events (2)
- # exercism (1)
- # figwheel-main (3)
- # fulcro (13)
- # graalvm (5)
- # gratitude (1)
- # inf-clojure (4)
- # introduce-yourself (5)
- # jobs-discuss (21)
- # lsp (36)
- # malli (6)
- # meander (8)
- # missionary (12)
- # off-topic (14)
- # pathom (13)
- # pedestal (10)
- # polylith (42)
- # re-frame (5)
- # reagent (12)
- # reitit (3)
- # releases (8)
- # sci (10)
- # shadow-cljs (37)
- # sql (5)
- # tools-deps (6)
I’ve been a little surprised today by the fact that combining a m/observe
and m/eduction
will cancel the observe flow unless there’s also a m/reduce
at the end (might also be described as “flow is cancelled if there’s no consumer “)
(def click-log
(->> (m/observe
(fn [!]
(.addEventListener js/window "click" !)
#(.removeEventListener js/window "click" !)))
(m/eduction (map js/console.log))))
(def cancel
(click-log #(js/console.log :done) #(js/console.log :error %)))
with this I’m getting a “consumer is not ready” errorobserve
is not backpressured, therefore it assumes the pipeline will process events fast enough. If not, the callback will throw "consumer is not ready". To prevent this, you should insert a relieve
stage between observe
and the slow consumer. If you're dealing with continuous values, the common idiom is to relieve with {}
, ie discard oldest value.
as an aside, this is not the right way to run a flow. The low-level protocol is significantly different from tasks, you should probably use reduce
or stream!
with reactor
instead, and only then run the resulting task
Is there an example of how to combine multiple flows into one somewhere? In particular I’m trying to build up subscriptions to a database into a sort of materialized view on the client. This involves combining multiple input flows (subscriptions)
but somewhere in the archives should be my conversation with @U053XQP4S from which I understand less than I would like 🙃
amb>
can be used to combine flows sequentially:
(m/?
(m/reduce
conj
(m/ap
(m/amb> (m/?> (m/seed [1 2 3]))
(m/?> (m/seed [4 5 6]))))))
returns [1 2 3 4 5 6]
I think latest
is what I was looking for! 🙂