leonoel / missionary

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

cycles in continuous time - distill the essence of problem, find correct patterns and provide helpers #99

Open leonoel opened 8 months ago

leonoel commented 8 months ago

There is a clear need for cyclic dataflow in continuous time. Cycles can be implemented with atom, watch and ?<, the pattern works but is hard to get right and involves a lot of boilerplate. with-cycle seems to be an interesting path forward, a synchronizer derived from ?< conceptually equivalent to the following implementation :

(defmacro with-cycle [[sym init] & body]
  (let [a# (atom ~init)
        ~sym (m/?< (m/watch a#))]
    (reset! a# (do ~@body))))

Open questions :