This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-21
Channels
- # announcements (3)
- # babashka (26)
- # beginners (45)
- # calva (10)
- # chlorine-clover (9)
- # cider (4)
- # clj-kondo (7)
- # cljs-dev (10)
- # clojure (95)
- # clojure-europe (33)
- # clojure-france (5)
- # clojure-nl (3)
- # clojure-spec (2)
- # clojure-sweden (3)
- # clojure-uk (33)
- # clojurescript (54)
- # conjure (101)
- # core-async (14)
- # cursive (1)
- # data-science (91)
- # datascript (3)
- # datomic (16)
- # figwheel (3)
- # figwheel-main (15)
- # fulcro (35)
- # ghostwheel (5)
- # graalvm (13)
- # helix (29)
- # java (5)
- # jobs (6)
- # kaocha (6)
- # leiningen (1)
- # meander (12)
- # off-topic (54)
- # pathom (13)
- # re-frame (16)
- # reagent (8)
- # reitit (4)
- # rum (3)
- # shadow-cljs (49)
- # spacemacs (2)
- # sql (5)
- # tools-deps (10)
- # xtdb (8)
- # yada (3)
If I have a task that needs a result and then to perform some "teardown" step, I could use a promise chan and a go block that takes from it then performs the teardown, and then return the promise-chan. Is this hacky, or is this idiomatic and one of the reasons for promise-chan
?
(defn mount-prom [parent child]
(let [ch (a/promise-chan
(comp (map #(array-seq (.-addedNodes %))) cat (keep #{child})))
mut (js/MutationObserver. (fn [muts] (go (a/onto-chan! ch muts))))]
(.observe mut parent #js {:childList true})
(go (<! ch) (.disconnect mut)) ;;once we have a value in the promise,
;;disconnection observer
ch))
because you are filtering things out of the promise-chan your clean up may never fire
onto-chan! has its own go-loop internally, so there is no need to wrap it in a go block
onto-chan! implies putting multiple values on to a channel, a promise-chan only ever has one
good points. I was depending on the filtering (via keep
) in the transducer to just ignore things until I get one I cared about, at which point it would be done
I think I saw the recent changes with onto-chan!
and it got in my head, but I didn't actually realzied it closed the chan once the items are copied, so I see that a doseq+put! would be better
Ohhh so I should probably just do the filtering in the callback before putting it in the channel?