@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
31 lines (30 loc) • 964 B
TypeScript
import type { NumberOfSeconds, PositiveInteger } from '@naturalcycles/js-lib/types';
import type { TransformOptions, TransformTyped } from '../stream.model.js';
export interface TransformThrottleOptions extends TransformOptions {
/**
* How many items to allow per `interval` of seconds.
*/
throughput: PositiveInteger;
/**
* How long is the interval (in seconds) where number of items should not exceed `throughput`.
*/
interval: NumberOfSeconds;
}
/**
* Allows to throttle the throughput of the stream.
* For example, when you have an API with rate limit of 5000 requests per minute,
* `transformThrottle` can help you utilize it most efficiently.
* You can define it as:
*
* _pipeline([
* // ...
* transformThrottle({
* throughput: 5000,
* interval: 60,
* }),
* // ...
* ])
*
* @experimental
*/
export declare function transformThrottle<T>(opt: TransformThrottleOptions): TransformTyped<T, T>;