MCPcopy
hub / github.com/tensorflow/tfjs / debounce

Function debounce

tfjs-layers/src/utils/generic_utils.ts:487–502  ·  view source on GitHub ↗
(
    f: (...args: Array<{}>) => T, waitMs: number,
    nowFunc?: Function)

Source from the content-addressed store, hash-verified

485 * @param waitMs The time between two consecutive calls to `f` in ms.
486 */
487export function debounce<T>(
488 f: (...args: Array<{}>) => T, waitMs: number,
489 nowFunc?: Function): (...args: Array<{}>) => T {
490 let lastTime = nowFunc != null ? nowFunc() : util.now();
491 let lastResult: T;
492 const f2 = (...args: Array<{}>) => {
493 const now = nowFunc != null ? nowFunc() : util.now();
494 if (now - lastTime < waitMs) {
495 return lastResult;
496 }
497 lastTime = now;
498 lastResult = f(...args);
499 return lastResult;
500 };
501 return f2;
502}
503
504/**
505 * Returns the fusable activation given a layers identifier.

Callers

nothing calls this directly

Calls 1

nowMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…