Skip to content

Instantly share code, notes, and snippets.

@raspasov
Created March 12, 2015 18:21
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 raspasov/d006968103b6854a4565 to your computer and use it in GitHub Desktop.
Save raspasov/d006968103b6854a4565 to your computer and use it in GitHub Desktop.
core.async sample
(ns my-project.test-core-async
(:require [clojure.core.async :refer [chan thread sliding-buffer timeout go <! <!! >!! >! go-loop put! thread alts!! alts! dropping-buffer pipeline-blocking]]))
(def events-ch (chan 1000))
;alternatively, try a sliding buffer if events can't be processed fast enough
;in GUI one **usually** cares about latest instead of *all* events
;Defaults to buffer size to 1000, that can be tuned based on use case
;(def events-ch (chan (sliding-buffer 1000)))
(defn start-go-loop
"Starts a processing go loop that takes events out of the events-ch;
No IO should be performed directly inside the go loop;
If one needs IO look into (thread)"
[]
(go (loop []
(let [msg (<! events-ch)]
(println "got msg:" msg)
(recur)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment