MCPcopy Create free account
hub / github.com/AztecProtocol/aztec-packages / executeTimeout

Function executeTimeout

yarn-project/foundation/src/timer/timeout.ts:81–93  ·  view source on GitHub ↗
(
  fn: (signal: AbortSignal) => Promise<T>,
  timeout: number,
  errorOrFnName?: string | (() => Error),
  onAbort?: () => void,
)

Source from the content-addressed store, hash-verified

79 *
80 * */
81export async function executeTimeout<T>(
82 fn: (signal: AbortSignal) => Promise<T>,
83 timeout: number,
84 errorOrFnName?: string | (() => Error),
85 onAbort?: () => void,
86) {
87 const errorFn =
88 typeof errorOrFnName === 'function'
89 ? errorOrFnName
90 : () => new TimeoutError(`Timeout running ${errorOrFnName ?? 'function'} after ${timeout}ms.`);
91 const task = new TimeoutTask(fn, timeout, errorFn, onAbort);
92 return await task.exec();
93}
94
95/** Returns a promise that rejects after the given timeout */
96export function timeoutPromise(timeoutMs: number, errorMessage?: string) {

Calls 1

execMethod · 0.95

Tested by

no test coverage detected