withTimeout()
The enaio contract defines no response guarantee. withTimeout is the
primitive that makes every host interaction that awaits a reply bounded —
the init wait, the facade method calls, everything.
1. Signature
withTimeout<T>(
work: () => PromiseLike<T>,
timeoutMs: number,
operation?: string, // defaults to 'host wait'
): Promise<T>;
Races work() against a timer:
-
resolves with the work’s result when it settles first;
-
rejects with a
TimeoutError(operation, timeoutMs)when the bound elapses first; -
always cleans up the timer (and `unref`s it where the API exists, so library-internal timers never keep a Node process alive).
A settling work after the bound is ignored (first settle wins).
2. Constants
DEFAULT_TIMEOUT_MS // 5000 — the default response timeout in ms
Both DEFAULT_TIMEOUT_MS and TimeoutError are exported from the package
root (see error model for the full error
classification; DashletOptions.timeoutMs is how
the bound is configured).