Fork me on GitHub
#missionary
<
2022-03-18
>
ribelo08:03:49

Is there any way to know that the flow has been closed and there will be no more items in the stream?

ribelo08:03:55

let's say I'd like to display a spinner from the start of the data download until the end.

ribelo08:03:14

I know I can use reduce, but maybe there is another way?

leonoel09:03:03

a flow has no identity, you cannot close it

leonoel09:03:47

please be more specific

ribelo09:03:00

being more specific is a big problem for me, but I will try 🙃

ribelo09:03:52

(defn some-random-flow []
  (let [xs (vec (range (rand-int 1000)))]
    (mi/seed xs)))

(defn some-fn []
  (mi/ap
   (show-spinner)
   (let [x (mi/?> (some-random-flow))]
     <<some body>>)
   (hide-spinner)))

ribelo09:03:05

I am currently doing something like this, but it does not look idiomatic

(defn some-fn []
  (mi/ap
   (show-spinner)
   (loop [[x & more] (mi/reduce conj (some-random-flow))]
     <<loop body>>)
   (hide-spinner)))

leonoel09:03:16

It's not currently possible to bind a resource lifecycle to a flow. I've thought about it for a long time and could not find a clever solution, so the way to go for now is to turn the flow into a task and use sp with try/finally.

👍 1