leonoel / missionary

A functional effect and streaming system for Clojure/Script
Eclipse Public License 2.0
651 stars 26 forks source link

`stream` double subscriptions - document correct pattern + investigate bug #98

Open leonoel opened 11 months ago

leonoel commented 11 months ago

From adamfrey on slack :

  (do
    ;; keeping track of how many times the fl flow runs
    (def *run-count (atom 0))
    (def fl
      (m/ap
        (let [i (m/?> (m/seed (range 10)))]
          (swap! *run-count inc)
          i)))

    ;; creating a publisher for multiple subscribers
    (def fl-stream (m/stream fl))

    (defn my-rf
      ([] [])
      ([acc] acc)
      ([acc x]
       (println "rf" x)
       (conj acc x)))

    (def joined
      (m/join vector
        (m/reduce my-rf (m/eduction (map #(* % 10)) fl-stream))
        (m/reduce my-rf (m/eduction (map #(* % 100)) fl-stream))))

    ;; (m/? joined) hangs forever
    (joined prn prn) ;; only reduces the first eduction

    ;; question: am I incorrectly initializing multiple subscribers to my stream?

    @*run-count
    )

Notes :

awb99 commented 1 day ago

Why does it need memo?