Add timeout error

This commit is contained in:
Andras Schmelczer 2026-01-18 22:13:33 +00:00
commit 4fb4b498a1

View file

@ -1,3 +1,5 @@
import { __debug_locks } from "sync-client";
export async function withTimeout<T>(
promise: Promise<T>,
timeoutMs: number,
@ -8,9 +10,16 @@ export async function withTimeout<T>(
new Promise<T>((_, reject) =>
setTimeout(() => {
reject(
new Error(`${operationName} timed out after ${timeoutMs}ms`)
new TimeoutError(`${operationName} timed out after ${timeoutMs}ms ${__debug_locks.map(lock => lock.getDebugString()).join(", ")}`)
);
}, timeoutMs)
)
]);
}
export class TimeoutError extends Error {
constructor(message: string) {
super(message);
this.name = "TimeoutError";
}
}