Last active
November 4, 2015 15:10
-
-
Save jooyunghan/39f3f02d935426a3e440 to your computer and use it in GitHub Desktop.
Throttle-first operator which ignores the following events with same key within `duration`
This file contains hidden or 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-first [duration keyF] | |
(operator* | |
(fn [s] | |
(let [cache (atom #{})] | |
(subscriber | |
s | |
(fn [s v] | |
(let [k (keyF v)] | |
(when-not (@cache k) | |
(on-next s v) | |
(swap! cache conj k) | |
(set-timeout #(swap! cache disj k) duration))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment