This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Hi guys! It's valid to do computation in the function of m/reduce
like this example:
(def !x (atom {}))
(defn on-change! [event]
(m/? (m/join vector (m/via m/blk (f1)) (m/via m/blk (f2)))))
(def run-listener
(let [<event (m/signal (m/watch !x))]
(m/reduce (fn [_ event] (on-change! event)) nil <event)))
m/? inside clojure fn (as opposed to m/sp m/ap etc) is blocking
you only want to block inside the m/via threadpool
try using m/? inside m/cp instead, so that the reduce callback is fast
do the slow computation right before the reduce if possible i’m saying - hard to discern your intent here
Thanks Dustin. The !x
atom holding some redis counters. Every 30s, this atom is updated and I want to perform some task on the new atom value.
(defn on-change [event]
(m/join vector (m/via m/blk (f1)) (m/via m/blk (f2))))
(def run-listener
(m/reduce (constantly nil)
(m/ap (m/? (on-change (m/?> (m/watch !x)))))))