Skip to content

Instantly share code, notes, and snippets.

@xfsnowind
Last active October 24, 2015 00:03
Show Gist options
  • Save xfsnowind/3a145751a881c179a7ce to your computer and use it in GitHub Desktop.
Save xfsnowind/3a145751a881c179a7ce to your computer and use it in GitHub Desktop.
usage debounce-clj on blog "Debounce and Throttle in Clojure" on 2015/10/24
(def sync-source (chan))
(def sync-sink (debounce sync-source 10000))
(defn handle-event! [event]
(when-let
[handler (case (:type event)
:one-event function-wanna-call
unknown-event)]
(try
(apply handler (:args event))
(catch Exception e nil))))
(go-loop [] (handle-event! (<! sync-sink)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment