Last active
August 29, 2015 14:23
-
-
Save ottbot/f2ffc9b8abbb64dac1dd to your computer and use it in GitHub Desktop.
throttling with manifold
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 throttle-example | |
(:require [manifold.stream :as s])) | |
;; should limit to 1 per sec ? | |
(def a (s/throttle 1 (s/stream))) | |
(dotimes [n 100] | |
(s/put! a n)) | |
(defn now [] | |
(new java.util.Date)) | |
(dotimes [n 10] | |
(println (str (now) " ~ " @(s/take! a)))) | |
;; Wed Jun 17 22:34:52 PDT 2015 ~ 0 | |
;; Wed Jun 17 22:34:52 PDT 2015 ~ 1 | |
;; Wed Jun 17 22:34:52 PDT 2015 ~ 2 | |
;; Wed Jun 17 22:34:52 PDT 2015 ~ 3 | |
;; Wed Jun 17 22:34:52 PDT 2015 ~ 4 | |
;; Wed Jun 17 22:34:52 PDT 2015 ~ 5 | |
;; Wed Jun 17 22:34:52 PDT 2015 ~ 6 | |
;; Wed Jun 17 22:34:52 PDT 2015 ~ 7 | |
;; Wed Jun 17 22:34:52 PDT 2015 ~ 8 | |
;; Wed Jun 17 22:34:52 PDT 2015 ~ 9 | |
;; just prints out real fast like. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to
put!
into the stream you've throttled, not the stream which was returned bythrottle
. In most of the operators I make it impossible toput!
into a derivative stream like this, it was an oversight on my part not to do the same here. Sorry for the confusion.