MCPcopy Create free account
hub / github.com/angular/angular / debounceForDuration

Function debounceForDuration

packages/forms/signals/src/api/rules/debounce.ts:64–82  ·  view source on GitHub ↗

* Creates a debouncer that will wait for the given duration before resolving.

(durationInMilliseconds: number)

Source from the content-addressed store, hash-verified

62 * Creates a debouncer that will wait for the given duration before resolving.
63 */
64function debounceForDuration(durationInMilliseconds: number): Debouncer<unknown> {
65 return (_context, abortSignal) => {
66 return new Promise((resolve) => {
67 let timeoutId: ReturnType<typeof setTimeout> | undefined;
68
69 const onAbort = () => {
70 clearTimeout(timeoutId);
71 resolve();
72 };
73
74 timeoutId = setTimeout(() => {
75 abortSignal.removeEventListener('abort', onAbort);
76 resolve();
77 }, durationInMilliseconds);
78
79 abortSignal.addEventListener('abort', onAbort, {once: true});
80 });
81 };
82}
83
84/**
85 * Creates a debouncer that will wait indefinitely, relying on the node to synchronize pending

Callers 1

normalizeDebouncerFunction · 0.85

Calls 4

setTimeoutFunction · 0.85
removeEventListenerMethod · 0.65
addEventListenerMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected