leonoel / missionary

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

observe callback must be a no-op after cancellation #5

Closed lgrapenthin closed 5 years ago

lgrapenthin commented 5 years ago

example from #4 in cljs

Unlike the CLJ version, this version yields a result. I. e. it prints

res [0 1 2]

But shortly after that, an uncaught type error is thrown in impl.cljs


(defn process-producer [event-fn]
  (let [step
        (fn step [i]
          (if (= 5 i)
            nil
            (js/setTimeout (fn []
                             (event-fn i)
                             (step (inc i)))
                           1000)))]
    (step 0)
    (fn []
      (.log js/console "Process producer cancelled"))))

(defn printer [t]
  (t (fn [res] (println "res" res))
     (fn [err] (println "err" err))))

(def inst
  (printer (->> (m/observe
                 process-producer)
                (m/transform (take 3))
                (m/aggregate conj))))
leonoel commented 5 years ago

Bug. It should not really happen because unsubscription is supposed to prevent the event callback from being called again, but if it happens anyhow the callback should return normally.