Last active
December 21, 2015 04:48
-
-
Save halgari/6251731 to your computer and use it in GitHub Desktop.
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
(defn throttle-chan [input] | |
(let [throttle-chan (chan) | |
output-chan (chan)] | |
(go | |
(loop [throttle-msec nil] | |
(let [t-chan (when-not (= :disabled throttle-msec) | |
(timeout throttle-msec)) | |
[val c] (alt! [input throttle-chan])] | |
(if (= c throttle-chan) | |
(recur val) | |
(do | |
(>! output-chan val) | |
(when t-chan | |
(<! t-chan)) | |
(recur throttle-msec)))))) | |
[output-chan throttle-chan])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A way to toggle