Skip to content

Instantly share code, notes, and snippets.

@johnbendi
Last active August 29, 2015 14:07
Show Gist options
  • Save johnbendi/e3f653b71269ddf46128 to your computer and use it in GitHub Desktop.
Save johnbendi/e3f653b71269ddf46128 to your computer and use it in GitHub Desktop.
Pedestal sample application not working properly
;; clj
;; ===
(def stored-event-channel (atom nil))
(defn start-foo-events [ctx]
(async/go (loop [n 1000]
(Thread/sleep 10)
(async/>! @stored-event-channel "ping")
(recur (dec n)))
(async/close! @stored-event-channel)))
(defbefore handle-foo-event [ctx]
(let [ctx (sse/start-stream (fn [c] (swap! stored-event-channel (constantly c))) ctx 10)]
(if @stored-event-channel (start-foo-events ctx))
ctx))
(def routes
(expand-routes
'[[["/msgs/:foo/:baz" handle-foo-event]]]))
;; cljs (In the browser)
;; ====
(def evt-src (atom nil))
(defn start-reload-event []
(let [pathname (.-pathname js/window.location)
es (js/EventSource. (str "/msgs" pathname))]
(swap! evt-src (constantly es))
(.log js/console "Starting event source..")
(.addEventListener es "event"
(fn [e]
(.log js/console e))
false)))
(start-reload-event)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment