most-limiter
TypeScript icon, indicating that this package has built-in type declarations

0.0.11 • Public • Published

most-limiter

Version License

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))

/most-limiter/

    Package Sidebar

    Install

    npm i most-limiter

    Weekly Downloads

    3

    Version

    0.0.11

    License

    BSD-3-Clause

    Unpacked Size

    4.58 kB

    Total Files

    5

    Last publish

    Collaborators

    • craft-ai