diff --git a/ts/index.ts b/ts/index.ts index 447f87f..c48fc5b 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -84,15 +84,23 @@ export const map = async (inputArg: T[], functionArg: IAsyncFunction) => { return resultArray; }; -export const timeoutWrap = (promiseArg: Promise, timeoutInMs: number) => { +export const timeoutWrap = async (promiseArg: Promise, timeoutInMsArg: number, rejectArg = true) => { return new Promise((resolve, reject) => { setTimeout(() => { - reject(new Error('timeout')); - }, timeoutInMs); + if (rejectArg) { + reject(new Error('timeout')); + } else { + resolve(null); + } + }, timeoutInMsArg); promiseArg.then(resolve, reject); }); }; +export const timeoutAndContinue = async (promiseArg: Promise, timeoutInMsArg = 60000) => { + return timeoutWrap(promiseArg, timeoutInMsArg, false); +} + export const getFirstTrueOrFalse = async (promisesArg: Promise[]) => { const done = defer(); for (const promiseArg of promisesArg) {