Rolling Window Throttler for Node.js
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.gitignore
.npmignore
.travis.yml
LICENSE.md
README.md
index.js
package.json

README.md

Rolling Window Throttler Build Status npm version

Count invocations per key and returns true if invocation allowed within provided durationWindow and max invocations per key.

Install

npm install --save rolling-window-throttler

Usage

const rollingWindowThrottler = require('rolling-window-throttler')
const throttler = rollingWindowThrottler({max: 1, durationWindow: '1s'})

if (throttler.tryAcquire('some-key')) {
  // not throttled, perform logic
}

Api

({max, durationWindow}): RollingWindowThrottler

Create new instance of RollingWindowThrottler.

Parameters:

  • max - int, mandatory, number of allowed invocations for a key;
  • durationWindow - mandatory and can be one of:
    • ms, ex. {durationWindow: 1000};
    • verbal period, ex. {durationWindow: '1m' / '1s' / '1hr 20mins'} as per parse-duration.

RollingWindowThrottler.tryAcquire(key): boolean

Returns true if not throttled for provided key.

License

Copyright (c) 2014 Wix.com Ltd. All Rights Reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file in the root of the source tree.