                         :while msg
                         :when msg]
                   (history/update script_name msg)
-                  (put! resp (format "data: %s\n\n" (generate-string msg))))
+                  (put! resp (format "data: %s\n\n" (generate-string msg)))
+                  (put! publisher (merge {:topic :events} msg)))
                 (catch Exception e
                   (error e "cannot handle incoming message"))
                 (finally

            (engine/request engine
                            (api/prepare scenario profile matchargs args)
                            ch)
            {:status 200
             :headers headers
             :body resp}))

   :headers {"Content-Type" "application/json"}
   :body (generate-string body)})

(defn yield-msg
  [chan]
  (alts!! [chan (timeout 15000)]))

(defn api-routes
  [scenarios engine {:keys [origins] :or {origins []}}]

  (let [patterns    (mapv re-pattern origins)
        publisher   (chan)
        publication (pub publisher #(:topic %))]
    (routes
     (GET "/scenarios" []
          (json-response (api/all! scenarios)))
