missionary

J 2024-03-29T08:34:50.092889Z

Hi guys! What is the convention to adopt in the codebase with a lot of missionary task? For example consider the following example:

;; Let the caller apply the missionary wrapper

(defn function-1 [] ...)

(def main
  (m/sp
    (let [res-1 (m/? (m/sp (function-1)))]

;; Or provide extra function to do the job

(defn function-1 [] ...)
(defn ?function-1 [] (m/? (m/sp (function-1)))

(def main
  (m/sp
    (let [res-1 (?function-1)])
  

leonoel 2024-03-29T13:22:23.189919Z

Let the caller choose. It's always possible to turn an asynchronous task into a synchronous one but the opposite is not true, so async should be the default

👍 2
Andrew Wilcox 2024-03-29T23:25:47.466749Z

Is there a simple way to merge discrete flows: to create an output flow which outputs all values from inputs flows as they occur? I could have the input flows publish to a mbx and construct the output flow from the values fetched from the mbx. The output flow should terminate when all input flows have terminated, so perhaps an input flow would publish a special terminated message to the mbx on terminating, the output process would count the termination messages and terminate when it got the same number of termination messages as input flows. Is there a simpler way to do this?

leonoel 2024-03-30T07:01:29.027199Z

yes, this one

🙏 1
Andrew Wilcox 2024-03-30T01:45:27.504359Z

This seems to work, but why doesn't it go into an infinite loop when the inputs flows terminate?

(defn merge-flows [>i1 >i2]
  (m/ap
   (loop []
     (m/amb
      (m/amb= (m/?> >i1) (m/?> >i2))
      (recur)))))

Andrew Wilcox 2024-03-30T01:57:02.414789Z

oh...

(defn merge-flows [>i1 >i2]
  (m/ap
   (m/amb= (m/?> >i1) (m/?> >i2))))

Andrew Wilcox 2024-03-29T23:30:06.850789Z

From the documentation, it looks like there isn't a way to terminate the flow created by observe ? The flow can be cancelled of course, but there isn't a way to have it act like e.g. (seed [1 2 3]), i.e. output some values and then terminate without cancellation? (It's fine if not, there's other ways to do it of course, just wanted to check my understanding).

leonoel 2024-03-30T08:15:14.845019Z

correct

🙏 1