Fork me on GitHub
#missionary
<
2023-02-12
>
denik17:02:45

what’s the idiomatic approach to running a continuous missionary flow in the background? e.g.

(def rand-flow
  (m/ap
    (loop []
      (m/amb
        (rand)
        (do (m/? (m/sleep 6e3)) (m/amb))
        (recur)))))
I ran this blocking in the REPL like
(m/? (m/reduce (fn [_ v]
                 (println v))
               nil
               rand-flow))
but how can I run this in my program without blocking? given the underlying fiber impl it seems unusual to put the process into a java.lang.Thread

xificurC18:02:28

https://github.com/leonoel/task#task-1

(def cancel (my-task #(prn :ok %) #(prn :err %)))

🙏 2
denik18:02:47

and a continuous flow will never call the :ok fn, correct?

xificurC18:02:06

The last 2 branches of your example can be joined

xificurC18:02:47

(do (m/? (m/sleep 6e3)) (recur))

denik18:02:03

and it should be run as a task?

denik18:02:08

even though it’s a continuous flow?

denik18:02:39

I guess flows always run within tasks since tasks are finite as is everything? 😄

xificurC18:02:09

Depends on the use case, maybe it could be done differently, but there's certainly nothing wrong running it as a task

leonoel20:02:35

finite vs infinite is orthogonal to task vs flow. finite task : (m/sp 42) infinite task : m/never finite flow : (m/seed [:a :b :c]) infinite flow : (m/watch !x)

👍 4
denik20:02:42

Right, a continuous flow is infinite, correct?

leonoel20:02:49

Conceptually, yes. but the process can still terminate. Trivial example : (m/cp 42) the state is indefinitely the same, but the process terminates immediately

leonoel20:02:33

More generally, a continuous flow can terminate to signify that its state won't change anymore.

denik20:02:08

Got it. Thanks for clarifying!