diff options
Diffstat (limited to 'apps/workers/utils.ts')
| -rw-r--r-- | apps/workers/utils.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/apps/workers/utils.ts b/apps/workers/utils.ts new file mode 100644 index 00000000..2f56d3f0 --- /dev/null +++ b/apps/workers/utils.ts @@ -0,0 +1,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, + ), + ), + ]); + }; +} |
