rolling-window-throttler

1.0.3 • Public • Published

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.

Package Sidebar

Install

npm i rolling-window-throttler

Weekly Downloads

5

Version

1.0.3

License

SEE LICENSE IN LICENSE.md

Last publish

Collaborators

  • kfiron