How to use the limiter.TokenBucket function in limiter

To help you get started, we’ve selected a few limiter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tjgq / node-stream-throttle / src / throttle.js View on Github external
function ThrottleGroup(opts) {
    if (!(this instanceof ThrottleGroup))
        return new ThrottleGroup(opts);

    opts = opts || {};
    if (opts.rate === undefined)
        throw new Error('throttle rate is a required argument');
    if (typeof opts.rate !== 'number' || opts.rate <= 0)
        throw new Error('throttle rate must be a positive number');
    if (opts.chunksize !== undefined && (typeof opts.chunksize !== 'number' || opts.chunksize <= 0)) {
        throw new Error('throttle chunk size must be a positive number');
    }

    this.rate = opts.rate;
    this.chunksize = opts.chunksize || this.rate/10;
    this.bucket = new TokenBucket(this.rate, this.rate, 'second', null);
}
github mathiasvr / youtube-terminal / lib / ascii-video.js View on Github external
function ThrottleStream (chunksPerSecond) {
  var bucket = new TokenBucket(chunksPerSecond, chunksPerSecond, 'second', null)

  return through2(function (chunk, _, next) {
    bucket.removeTokens(1, function (err) {
      next(err, chunk)
    })
  })
}

limiter

A generic rate limiter for the web and node.js. Useful for API clients, web crawling, or other tasks that need to be throttled

MIT
Latest version published 11 months ago

Package Health Score

71 / 100
Full package analysis

Popular limiter functions