Last active
August 29, 2015 13:58
-
-
Save jphackworth/9976671 to your computer and use it in GitHub Desktop.
Basic queuing with Lamina
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
;;; Lamina queueing | |
(def job-queue (lamina/channel)) | |
(def worker-interval (atom 250)) | |
(defn consume-jobs [] | |
(let [{:keys [c f args] :as msg} | |
@(lamina/read-channel job-queue)] | |
(Thread/sleep @worker-interval) | |
(lamina/enqueue c (apply f args)))) | |
(defn job-consumer [] | |
(doall (repeatedly consume-jobs))) | |
(defn start-job-consumer [] | |
(-> (Thread. job-consumer) .start)) | |
; FIXME: Enqueue needs job-consumer thread to have already been started | |
(defn add-to-queue [f & args] | |
(lamina/run-pipeline (lamina/channel) | |
(fn [ch] | |
(lamina/enqueue job-queue {:c ch :f f :args args}) | |
(lamina/read-channel ch)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment