Datasets:
File size: 312 Bytes
8d88d9b |
1 2 3 4 5 6 7 8 9 10 |
export const timeout = <T>(prom: Promise<T>, time: number): Promise<T> => {
let timer: NodeJS.Timeout;
return Promise.race([
prom,
new Promise<T>((_, reject) => {
timer = setTimeout(() => reject(new Error(`Timeout after ${time / 1000} seconds`)), time);
}),
]).finally(() => clearTimeout(timer));
};
|