Skip to content

Instantly share code, notes, and snippets.

@jcf
Created February 9, 2017 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcf/aea2a9682ce6c65d57c905cccb25c885 to your computer and use it in GitHub Desktop.
Save jcf/aea2a9682ce6c65d57c905cccb25c885 to your computer and use it in GitHub Desktop.
Slurp the contents of your Onyx log into memory
(defn slurp-log
([peer-client-config] (slurp-log peer-client-config 2000))
([peer-client-config wait]
(let [chan (clojure.core.async/chan)
sub (onyx.api/subscribe-to-log peer-client-config chan)
timeout (clojure.core.async/timeout wait)
xs (clojure.core.async/<!!
(clojure.core.async/go-loop [xs []]
(let [[val ch] (clojure.core.async/alts! [chan timeout])]
(if (= ch timeout)
xs
(recur (conj xs val))))))]
(-> sub :env onyx.api/shutdown-env)
xs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment