Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
leonoel opened this issue Nov 2, 2023 · 1 comment

Comments

@leonoel
Copy link
Owner

leonoel commented Nov 2, 2023

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 :

  • the correct behavior requires adding a m/memo after m/join, the pattern is not obvious and should be documented.
  • the wrong behavior should not hang forever, it is likely a bug
@awb99
Copy link

awb99 commented Oct 4, 2024

Why does it need memo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants