blob: 2f56d3f04d547ed46494b02e8f09668d6a4bc2f6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
export function withTimeout<T, Ret>(
func: (param: T) => Promise<Ret>,
timeoutSec: number,
) {
return async (param: T): Promise<Ret> => {
return await Promise.race([
func(param),
new Promise<Ret>((_resolve, reject) =>
setTimeout(
() => reject(new Error(`Timed-out after ${timeoutSec} secs`)),
timeoutSec * 1000,
),
),
]);
};
}
|