@mollie/api-client
Version:
Official Mollie API client for Node
21 lines (20 loc) • 937 B
TypeScript
/**
* Keeps track of the number of values which have been consumed, as well as the timeframe during which they were
* consumed. The `throttle` method can be used to throttle if more values are consumed than allowed at any given moment
* in time (overconsumption), as dictated by the `valuesPerMinute` argument passed into the constructor.
*/
export default class Throttler {
protected count: number;
protected readonly start: number;
protected readonly valuesPerSixSeconds: number;
constructor(valuesPerMinute: number);
/**
* Registers that the passed number of values have been consumed.
*/
tally(count: number): void;
/**
* If more values have been consumed than allowed at this moment in time (overconsumption), a promise is returned
* which is resolved as soon as this is no longer the case. Otherwise, `undefined` is returned.
*/
throttle(): Promise<void> | undefined;
}