File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -15,19 +15,28 @@ export type DebounceOptions = {
1515 *
1616 * @example
1717 * ```ts
18- * const debouncedSave = debounce(() => saveData(), { delay: 1000 });
18+ * import { debounce } from "./debounce.ts";
19+ * import { delay } from "jsr:@std/async@^1.0.0/delay";
20+ *
21+ * const saveData = () => console.log("Saving data...");
22+ * const debouncedSave = debounce(() => saveData(), { delay: 100 });
1923 *
20- * // Multiple calls within 1000ms will only trigger one save
24+ * // Multiple calls within 100ms will only trigger one save
2125 * debouncedSave();
2226 * debouncedSave();
2327 * debouncedSave();
28+ *
29+ * // Wait for the debounced function to execute
30+ * await delay(150);
2431 *
2532 * // Cancel via AbortSignal
33+ * const doWork = () => console.log("Doing work...");
2634 * const controller = new AbortController();
2735 * const debouncedFunc = debounce(() => doWork(), {
28- * delay: 500 ,
36+ * delay: 50 ,
2937 * signal: controller.signal
3038 * });
39+ * debouncedFunc();
3140 * controller.abort(); // Cancels any pending execution
3241 * ```
3342 */
You can’t perform that action at this time.
0 commit comments