 (ns onyx.api
   (:require [clojure.string :refer [split]]
-            [clojure.core.async :refer [chan >!! <!! close! alts!! timeout go]]
+            [clojure.core.async :refer [chan >!! <!! close! alts!! timeout go promise-chan]]
             [com.stuartsierra.component :as component]
             [taoensso.timbre :refer [info warn fatal error]]
             [onyx.log.entry :refer [create-log-entry]]

              (= ch restart-ch)
              (do (component/stop live)
                  (Thread/sleep (or (:onyx.peer/retry-start-interval config) 2000))
                  (when-let [live (restart-peer live shutdown-ch)]
                    (do (reset! started-peer live)
                        (recur live))))
              :else (throw (ex-info "Read from a channel with no response implementation" {})))))
    (catch Throwable e
      (fatal "Peer lifecycle threw an exception")

     (fn [_]
       (let [v-peer (system/onyx-peer peer-group monitoring-config)
             live (component/start v-peer)
             shutdown-ch (promise-chan)
             ack-ch (promise-chan)
             started-peer (atom live)]
         {:peer-lifecycle (future (peer-lifecycle started-peer config shutdown-ch ack-ch))
          :started-peer started-peer
