MCPcopy Create free account
hub / github.com/Snapchat/Valdi / debounce

Function debounce

valdi/vscode_debugger/src/common/objUtils.ts:236–257  ·  view source on GitHub ↗
(duration: number, fn: () => void)

Source from the content-addressed store, hash-verified

234 * Debounces the function call for an interval.
235 */
236export function debounce(duration: number, fn: () => void): (() => void) & { clear: () => void } {
237 let timeout: NodeJS.Timer | void;
238 const debounced = () => {
239 if (timeout !== undefined) {
240 clearTimeout(timeout);
241 }
242
243 timeout = setTimeout(() => {
244 timeout = undefined;
245 fn();
246 }, duration);
247 };
248
249 debounced.clear = () => {
250 if (timeout) {
251 clearTimeout(timeout);
252 timeout = undefined;
253 }
254 };
255
256 return debounced;
257}
258
259/**
260 * Bisets the array by the predicate. The first return value will be the ones

Callers 4

index.tsFile · 0.90
CorrelatedCacheClass · 0.90
constructorMethod · 0.90
constructorMethod · 0.50

Calls 1

clearTimeoutFunction · 0.50

Tested by

no test coverage detected