Add timeout error
This commit is contained in:
parent
cb2d82ab44
commit
4fb4b498a1
1 changed files with 13 additions and 4 deletions
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue