@johngw/stream
Version:
Reactive programming tools using the WHATWG Streams API.
46 lines (45 loc) • 1.25 kB
text/typescript
import { DebounceBehavior } from '#transformers/debounce/Behavior';
import { DebounceState } from '#transformers/debounce/State';
/**
* @group Transformers
*/
export interface DebounceBackOffBehaviorOptions {
/**
* The back-off increment formular
*/
inc(currentMS: number): number;
/**
* An optional maximum time to reach.
*
* @default Number.MAX_SAFE_INTEGER
*/
max?: number;
}
/**
* A behavior that will increase the debounce time whenever events
* are received within the current time. It's best to be used in
* conjunction with the {@link DebounceTrailingBehavior:class}
* or the {@link DebounceLeadingBehavior:class}.
*
* @group Transformers
* @see {@link debounce:function}
* @example
* --a--b---c----d----|
*
* debounce(5, [
* new DebounceBackOffBehavior({ inc: (ms) => ms * 2 }),
* new DebounceTrailingBehavior(),
* ])
*
* --T5-T10-T20--T40-d-
*/
export declare class DebounceBackOffBehavior<T> implements DebounceBehavior<T> {
#private;
constructor({ inc, max, }: DebounceBackOffBehaviorOptions);
init(state: DebounceState): void;
preTimer(state: DebounceState): {
ms: number;
queued: boolean;
timer?: number | undefined;
};
}