fix(core): update

This commit is contained in:
2021-06-04 14:11:27 +02:00
parent 2dc91dc2f0
commit 5df94778dd
6 changed files with 54 additions and 25 deletions

View File

@ -5,7 +5,11 @@ import * as smartpromise from '@pushrocks/smartpromise';
* @param timeInMillisecondArg
* @param passOnArg
*/
export let delayFor = async <T>(timeInMillisecondArg: number, passOnArg?: T, unrefedArg = false) => {
export let delayFor = async <T>(
timeInMillisecondArg: number,
passOnArg?: T,
unrefedArg = false
) => {
const timeout = new Timeout(timeInMillisecondArg, null, unrefedArg);
await timeout.promise;
return passOnArg;
@ -20,7 +24,11 @@ export let delayForRandom = async <T>(
passOnArg?: T,
unrefedArg = false
) => {
await delayFor(Math.random() * (timeMaxInMillisecondArg - timeMinInMillisecondArg) + timeMinInMillisecondArg, null, unrefedArg)
await delayFor(
Math.random() * (timeMaxInMillisecondArg - timeMinInMillisecondArg) + timeMinInMillisecondArg,
null,
unrefedArg
);
return passOnArg;
};
@ -62,7 +70,7 @@ export class Timeout<T> {
this._cancelled = true;
clearTimeout(this._timeout);
}
public getTimeLeft() {
const result = this.started + this.timeoutInMillis - Date.now();
return result > 0 ? result : 0;