MCPcopy Create free account
hub / github.com/dethcrypto/dethcode / debounceAsyncFunc

Function debounceAsyncFunc

packages/ethereum-viewer/src/util/func.ts:76–91  ·  view source on GitHub ↗
(
  func: T,
  wait: number
)

Source from the content-addressed store, hash-verified

74
75// debounce an async func. once an async func canceled, it throws a exception
76export const debounceAsyncFunc = <T extends (...args: any[]) => Promise<any>>(
77 func: T,
78 wait: number
79) => {
80 let timer: Timeout | undefined;
81 let previousReject: ((reason?: any) => void) | undefined;
82
83 return function f(this: unknown, ...args: Parameters<T>): ReturnType<T> {
84 return new Promise((resolve, reject) => {
85 timer && clearTimeout(timer);
86 previousReject && previousReject();
87 timer = setTimeout(() => resolve(func.call(this, ...args)), wait);
88 previousReject = reject;
89 }) as ReturnType<T>;
90 };
91};
92
93type Timeout = ReturnType<typeof setTimeout>;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected