missionary

awb99 2024-08-04T23:39:15.269359Z

I got a weird behavior if I take one or two values from a signal:

leonoel 2024-08-05T07:48:01.207849Z

m/join boots all of its inputs sequentially and synchronously on boot. (m/reduce conj [] (m/eduction (take 1) conn)) performs the following actions synchronously on boot : • subscribes to conn • transfers one value • unsubscribes to conn • terminates In your example, the first input spawns the connection and cancels it immediately because there's no other subscription. If you want to ensure the connection is kept alive, you have to concurrently spawn a subscription with a larger lifespan.

awb99 2024-08-06T04:16:27.931499Z

Thanks for explaining the internals of join @leonoel I have naively assumed that all tasks would be started in parallel.

awb99 2024-08-04T23:39:51.566889Z

(ns demo.connection.signal (:require [nano-id.core :refer [nano-id]] [missionary.core :as m])) (def >conn (m/signal (m/ap (println "#### creating conn") (loop [c (nano-id 4)] (m/amb c (do (m/? (m/compel (m/sleep 10000 c))) (println "#### re-connecting .. ") (recur (nano-id 4)))))))) (m/? (m/join vector (m/reduce conj [] (m/eduction (take 1) >conn)) (m/reduce conj [] (m/eduction (take 2) >conn)) (m/sp (m/? (m/sleep 1)) (m/? (m/reduce conj [] (m/eduction (take 2) >conn))))) ) ;; => [["60Jb"] ["TO0J" "sdAK"] ["TO0J" "sdAK"]]

awb99 2024-08-04T23:41:00.922979Z

When I just take one value from the eduction then it starts the signal process two times.

awb99 2024-08-05T01:02:18.661489Z

What I have expected is that m/signal keeps Track of all subscribers .. and therefore the result for take1 should be the same as the first entry of take2.

awb99 2024-08-05T01:06:17.284659Z

It Seems to me that m/join does start the tasks sequentially .. and the the first value goes away so fast that the signal publishers gets shutdown before the next task gets started.

awb99 2024-08-05T01:06:46.503739Z

(m/? (m/join vector (m/reduce conj [] (m/eduction (take 2) conn)) (m/reduce conj [] (m/eduction (take 1) conn)) (m/reduce conj [] (m/eduction (take 2) conn)) (m/reduce conj [] (m/eduction (take 2) conn)) (m/reduce conj [] (m/eduction (take 2) conn)) (m/reduce conj [] (m/eduction (take 1) conn)) (m/reduce conj [] (m/eduction (take 1) conn)) (m/reduce conj [] (m/eduction (take 1) conn)) (m/sp (m/? (m/sleep 1)) (m/? (m/reduce conj [] (m/eduction (take 2) conn))))))

awb99 2024-08-05T01:07:24.271099Z

When the first eduction takes 2 values .. then all the values returned are as they should be.

awb99 2024-08-05T01:23:16.497809Z

Its surprising to me that m/join has this sort of unpredictable behavior.