Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit write frequency to core.async channel?

Is there an easy way to limit the write frequency to a core.async channel ? So far I could find two examples. One uses a sliding-buffer and some SetTimeout magic to handle this the other uses an external atom as a counter. I would have expected that core.async provides such functionality out of the box. Since one of the examples is rather old (10 month) I would like to know if theres is maybe an easier solution ?

I'm looking for a solution that works with Clojure and ClojureScript.

like image 682
rogergl Avatar asked Apr 21 '14 17:04

rogergl


1 Answers

The throttler lib provides functions to impose rate controls on Clojure code (including throttles on channels or functions).

From the readme:

(def in (chan 1))
(def slow-chan (throttle-chan in 1 :millisecond)) ; 1 msg/ms

(>!! in :token) ; => true
(<!! slow-chan) ; :token
like image 120
noisesmith Avatar answered Sep 20 '22 14:09

noisesmith