export function withTimeout( func: (param: T) => Promise, timeoutSec: number, ) { return async (param: T): Promise => { return await Promise.race([ func(param), new Promise((_resolve, reject) => setTimeout( () => reject(new Error(`Timed-out after ${timeoutSec} secs`)), timeoutSec * 1000, ), ), ]); }; }