leonoel / missionary

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

Subscription failure : not in publisher context. #43

Closed mjmeintjes closed 2 years ago

mjmeintjes commented 2 years ago

The following code

  (m/?
   (m/reactor
    (let [pub (m/stream! (m/seed [1 2]))]
      (m/stream!
       (m/ap
        (m/? (m/sleep 0))
        (println  (m/?> pub)))))))

throws

Execution error at missionary.impl.Reactor/<clinit> (Reactor.java:12).
Subscription failure : not in publisher context.

I was just wondering whether this is a bug, or expected behavior.

leonoel commented 2 years ago

This is expected behavior, it means you tried to change the graph topology outside of a propagation turn. In this example, the subscription to pub is triggered by the sleep, which is foreign to the reactor.

In this other example, the subscription is well defined, because it is triggered by another publisher.

(m/?
  (m/reactor
    (let [pub (m/stream! (m/seed [1 2]))
          evt (m/stream! (m/ap (m/? (m/sleep 0))))]
      (m/stream!
        (m/ap
          (m/?> evt)
          (println (m/?> pub)))))))

However println will not called because pub is already terminated when evt emits.