Rolling Window Throttler
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 = const throttler = if throttler // 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.