File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,26 @@ export interface ThrottledFunction<T extends Array<unknown>> {
7070 * assert(func.lastExecution > 0);
7171 * ```
7272 *
73+ * @example With dynamic timeframe
74+ *
75+ * ```ts no-assert
76+ * import { throttle } from "@std/async/unstable-throttle";
77+ *
78+ * function processUserInput(input: string) {
79+ * // Do some expensive computation with user input that changes on each
80+ * // keypress, which takes a variable amount of time depending on the length
81+ * // or complexity of input.
82+ * }
83+ *
84+ * const processUserInputThrottled = throttle(
85+ * processUserInput,
86+ * // Throttle dynamically, waiting twice as long as the previous execution
87+ * // took to complete before starting the next call.
88+ * (n) => n * 2,
89+ * { ensureLastCall: true },
90+ * );
91+ * ```
92+ *
7393 * @typeParam T The arguments of the provided function.
7494 * @param fn The function to throttle.
7595 * @param timeframe The timeframe in milliseconds in which the function should be called at most once.
You can’t perform that action at this time.
0 commit comments