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))
I think that's one of the primary reasons promise-chans exist
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! is also a super weird thing to use with a promise-chan
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
i think the question was more what are you putting many values into a promise chan
disconnect between multiple values into a channel that ignores subsequent values
Ohhh so I should probably just do the filtering in the callback before putting it in the channel?
and get rid of the transducer
and i think that relates to @hiredman's point that if you are filtering its possible you never get an acceptable value
yeah that's a good point to, I think I'll add a timeout option