import { __debug_locks } from "sync-client"; export async function withTimeout( promise: Promise, timeoutMs: number, operationName: string ): Promise { return Promise.race([ promise, new Promise((_, reject) => setTimeout(() => { reject( 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"; } }