         source-chans     (call-drivers drivers sink-proxy-chans)
         sink-chans       (main source-chans)
         _                (weld-cycle! sink-chans sink-proxy-chans)]
-    (println "cycle running")))
+    (println "cycle running")
+    (->> sink-proxy-chans vals shutdown-channel)))

(ns kierros.core
  "Cycle-flavoured core functions."
  (:require [cljs.core.async :as a :refer [<! chan]]))

(defn sink-proxies
  "Accepts a map of drivers. Returns a map of the equivalent of Rx.ReplaySubject instance

(defn weld-cycle!
  "Closes the cycle between the sinks and sink-proxies."
  [sink-chans sink-proxy-chans]
  (doseq [[key sink-chan] sink-chans]
    (when sink-chan
      (a/pipe sink-chan (key sink-proxy-chans)))))

(defn shutdown-channel
  "Accepts a colletion of channels. Returns the shutdown channel.
  When a signal is taken from the shutdown channel, all specified channels are closed."
  [chans]
  (let [shutdown-chan (chan 1)]
    (go
      (<! shutdown-chan)              ;; wait for the shutdown signal
      (doseq [ch chans] (close! ch))) ;; close all driver channels
    shutdown-chan))

(defn run
  "Cycle.run equivalent. Accepts a main function and a map of drivers."
