fix(core): update
This commit is contained in:
parent
1848006601
commit
4c3565c618
12
ts/index.ts
12
ts/index.ts
@ -84,15 +84,23 @@ export const map = async <T>(inputArg: T[], functionArg: IAsyncFunction<T>) => {
|
|||||||
return resultArray;
|
return resultArray;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const timeoutWrap = <T = any>(promiseArg: Promise<T>, timeoutInMs: number) => {
|
export const timeoutWrap = async <T = any>(promiseArg: Promise<T>, timeoutInMsArg: number, rejectArg = true) => {
|
||||||
return new Promise<T>((resolve, reject) => {
|
return new Promise<T>((resolve, reject) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
if (rejectArg) {
|
||||||
reject(new Error('timeout'));
|
reject(new Error('timeout'));
|
||||||
}, timeoutInMs);
|
} else {
|
||||||
|
resolve(null);
|
||||||
|
}
|
||||||
|
}, timeoutInMsArg);
|
||||||
promiseArg.then(resolve, reject);
|
promiseArg.then(resolve, reject);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const timeoutAndContinue = async <T = any>(promiseArg: Promise<T>, timeoutInMsArg = 60000) => {
|
||||||
|
return timeoutWrap(promiseArg, timeoutInMsArg, false);
|
||||||
|
}
|
||||||
|
|
||||||
export const getFirstTrueOrFalse = async (promisesArg: Promise<boolean>[]) => {
|
export const getFirstTrueOrFalse = async (promisesArg: Promise<boolean>[]) => {
|
||||||
const done = defer<boolean>();
|
const done = defer<boolean>();
|
||||||
for (const promiseArg of promisesArg) {
|
for (const promiseArg of promisesArg) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user