timed

@atiproto/edge-resolvers

Wraps an async function with an AbortSignal timeout. If the function does not resolve within ms milliseconds, the signal is aborted and the promise rejects with a timeout error. Used internally by EdgeDidPlcResolver and EdgeDidWebResolver.

Signature

typescript
function timed<T>(ms: number, fn: (signal: AbortSignal) => Promise<T>): Promise<T>
ParameterTypeDescription
msnumberTimeout in milliseconds. The AbortSignal fires after this duration.
fn(signal: AbortSignal) => Promise<T>The async work to perform. Receives the AbortSignal so it can be forwarded to fetch or other cancellable APIs.

Example

typescript
import { timed } from "@atiproto/edge-resolvers";
const data = await timed(3000, async (signal) => {
const res = await fetch("https://plc.directory/did:plc:abc123", { signal });
return res.json();
});