···11+import { IdentityResolutionTimeoutError } from "../errors.ts";
22+13/** A timed function to abort after a certain amount of time */
24export async function timed<F extends (signal: AbortSignal) => unknown>(
35 ms: number,
···9111012 try {
1113 return (await fn(signal)) as Awaited<ReturnType<F>>;
1414+ } catch (err) {
1515+ if (signal.aborted) {
1616+ throw new IdentityResolutionTimeoutError(ms, { cause: err });
1717+ }
1818+ throw err;
1219 } finally {
1320 clearTimeout(timer);
1421 abortController.abort();
+9
identity/errors.ts
···77 }
88}
991010+/** Error thrown when DID resolution exceeds its configured timeout.
1111+ * @param ms Timeout in milliseconds.
1212+ */
1313+export class IdentityResolutionTimeoutError extends Error {
1414+ constructor(public ms: number, options?: ErrorOptions) {
1515+ super(`DID resolution timed out after ${ms}ms`, options);
1616+ }
1717+}
1818+1019/**
1120 * Error thrown when a DID is not formatted correctly.
1221 * Most commonly, a DID missing `did:` at the beginning