From 80de670cadf931ae2497a84f21c4660bcaf1b9d0 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Wed, 27 May 2020 16:54:32 +0000 Subject: [PATCH] fix(core): update --- ts/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ts/index.ts b/ts/index.ts index 7af2f29..867223f 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -36,7 +36,11 @@ export class Timeout { private _timeout: any; private _cancelled: boolean = false; + private timeoutInMillis: number; + private started: number; + constructor(timeInMillisecondArg, passOn?: T) { + this.timeoutInMillis = timeInMillisecondArg; this._deferred = smartpromise.defer(); this.promise = this._deferred.promise; this._timeout = setTimeout(() => { @@ -44,6 +48,7 @@ export class Timeout { this._deferred.resolve(passOn); } }, timeInMillisecondArg); + this.started = Date.now(); } /** @@ -60,4 +65,9 @@ export class Timeout { this._cancelled = true; this.makeUnrefed(); } + + public getTimeLeft() { + const result = this.started + this.timeoutInMillis - Date.now(); + return result > 0 ? result : 0; + } }