Created
March 12, 2015 18:21
-
-
Save raspasov/d006968103b6854a4565 to your computer and use it in GitHub Desktop.
core.async sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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