most-limiter
v0.0.11
Published
Lossless rate limiter for most.js
Downloads
15
Maintainers
Readme
most-limiter
Lossless rate limiter for most.js.
Unlike most.debounce
or most.throttle
, with most-limiter
, each event gets through, unless the internal buffer overrides.
Installation
Using npm:
$ npm install --save most-limiter
In Node.js:
const limiter = require('most-limiter');
Usage
stream.thru(limiter(interval [, capacity = 1000])) -> Stream
stream: -a-b---cdef----->
stream.thru(limiter(100)): -a-b---c-d-e-f-->
interval
is the minimum time interval between events, in ms.capacity
is the maximum size of the internal buffer, overrides leads to an error.
const most = require('most');
const limiter = require('most-limiter');
// Logs
// 1
// 2 (after 500ms)
// 3 (after 500ms more)
most.iterate(x => x + 1, 0)
.take(3) // 3 first numbers
.thru(limiter(500)) // Limit to on event every 500ms
.observe(x => console.log(x))