2 Commits

Author SHA1 Message Date
3821799070 2.0.9 2020-05-27 16:54:33 +00:00
80de670cad fix(core): update 2020-05-27 16:54:32 +00:00
3 changed files with 12 additions and 2 deletions

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartdelay", "name": "@pushrocks/smartdelay",
"version": "2.0.8", "version": "2.0.9",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@@ -1,7 +1,7 @@
{ {
"name": "@pushrocks/smartdelay", "name": "@pushrocks/smartdelay",
"private": false, "private": false,
"version": "2.0.8", "version": "2.0.9",
"description": "timeouts for the async/await era, written in TypeScript", "description": "timeouts for the async/await era, written in TypeScript",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",

View File

@@ -36,7 +36,11 @@ export class Timeout<T> {
private _timeout: any; private _timeout: any;
private _cancelled: boolean = false; private _cancelled: boolean = false;
private timeoutInMillis: number;
private started: number;
constructor(timeInMillisecondArg, passOn?: T) { constructor(timeInMillisecondArg, passOn?: T) {
this.timeoutInMillis = timeInMillisecondArg;
this._deferred = smartpromise.defer<T>(); this._deferred = smartpromise.defer<T>();
this.promise = this._deferred.promise; this.promise = this._deferred.promise;
this._timeout = setTimeout(() => { this._timeout = setTimeout(() => {
@@ -44,6 +48,7 @@ export class Timeout<T> {
this._deferred.resolve(passOn); this._deferred.resolve(passOn);
} }
}, timeInMillisecondArg); }, timeInMillisecondArg);
this.started = Date.now();
} }
/** /**
@@ -60,4 +65,9 @@ export class Timeout<T> {
this._cancelled = true; this._cancelled = true;
this.makeUnrefed(); this.makeUnrefed();
} }
public getTimeLeft() {
const result = this.started + this.timeoutInMillis - Date.now();
return result > 0 ? result : 0;
}
} }