File size: 320 Bytes
3d23b0f |
1 2 3 4 5 6 7 8 9 10 |
export async function withTimeout<T>(promise: Promise<T>, timeoutMs: number, errorMessage: string): Promise<T> {
const timeout = new Promise<never>((_, reject) => {
setTimeout(() => {
reject(new Error(errorMessage));
}, timeoutMs);
});
return Promise.race([promise, timeout]);
}
|