This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-15
Channels
- # adventofcode (110)
- # announcements (30)
- # aws (2)
- # babashka (39)
- # babashka-sci-dev (112)
- # beginners (155)
- # calva (5)
- # cider (12)
- # clj-kondo (11)
- # cljs-dev (1)
- # cljsrn (2)
- # clojure (144)
- # clojure-australia (2)
- # clojure-europe (14)
- # clojure-nl (5)
- # clojure-spec (3)
- # clojure-uk (2)
- # clojurescript (22)
- # core-async (23)
- # cursive (31)
- # data-science (3)
- # emacs (12)
- # events (1)
- # fulcro (8)
- # honeysql (7)
- # jobs-discuss (11)
- # lsp (1)
- # missionary (28)
- # nextjournal (7)
- # off-topic (64)
- # pedestal (3)
- # polylith (19)
- # reagent (14)
- # reitit (12)
- # releases (4)
- # shadow-cljs (33)
- # tools-deps (3)
- # xtdb (3)
In this case, shouldn't the oldest values be discarded?
(def atm_ (atom 0))
(def >f (mi/watch atm_))
(def r ((mi/reduce (constantly nil)
(->> (mi/ap (let [x (mi/?> (mi/relieve {} >f))]
(mi/? (mi/sp (mapv inc (range 1e7)) x)))) ;; takes about 200msc
(mi/eduction (map prn) (take 10))))
prn prn))
(run! #(reset! atm_ %) (range 10))
but Cancelling an sp task triggers cancellation of the task it's currently running, along with all tasks subsequently run.
yes, but cancellation can only happen on specific points, and there aren't any in this one
by analogy to core.async
, how to get the identical result in that case?
(def c (a/chan (a/dropping-buffer 5)))
(def r (a/go (loop []
(when-let [v (a/<! c)]
(mapv inc (range 1e7))
(println v)
(recur)))))
(run! #(a/put! c %) (range 10))
(def m (m/mbx))
(def >input
(->> (m/ap (loop [] (m/amb> (m/? m) (recur))))
(m/relieve (fn [x _] x))
(m/buffer 5)))
(defn heavy [x]
(m/via m/cpu (mapv inc (range 1e7)) x))
(def r
((m/reduce {} nil
(m/ap (println (m/? (heavy (m/?> >input))))))
prn prn))
(run! m (range 10))
unlike go
blocks, sp
and ap
have no dedicated thread pool, therefore any cpu-intensive computation should be wrapped in a task with via cpu
you can insert a cancellation checkpoint with !
(defn heavy [x]
(m/via m/cpu (mapv (fn [x] (m/!) (inc x)) (range 1e7)) x))
Also, I tried using m/!
but it looks like it has no effect on anything and doesn't work
would you be so kind and show an example of how to use it? unfortunately I can't create any without using sleep
, where relieve
and !
works 😞