namirasoft-core
Advanced tools
Comparing version 1.4.32 to 1.4.34
export declare class SetTimeouService { | ||
private last; | ||
private last_date; | ||
private last_index; | ||
private onCalled; | ||
setTimeoutIfNotCalledAgain(callback: () => void, milliseconds: number): void; | ||
setTimeoutIfFarArrival(callback: () => void, milliseconds: number): void; | ||
} |
@@ -7,15 +7,28 @@ "use strict"; | ||
constructor() { | ||
this.last = new Date(); | ||
this.last_date = new Date(); | ||
this.last_index = 0; | ||
} | ||
onCalled(milliseconds) { | ||
this.last_index++; | ||
let l = TimeOperation_1.TimeOperation.millisecondsLater(milliseconds - 1, this.last_date); | ||
if (this.last_date < l) | ||
this.last_date = l; | ||
return this.last_index; | ||
} | ||
setTimeoutIfNotCalledAgain(callback, milliseconds) { | ||
let l = TimeOperation_1.TimeOperation.millisecondsLater(milliseconds - 1, this.last); | ||
if (this.last < l) | ||
this.last = l; | ||
let index = this.onCalled(milliseconds); | ||
setTimeout(() => { | ||
if (this.last < new Date()) | ||
if (index === this.last_index) | ||
callback(); | ||
}, milliseconds); | ||
} | ||
setTimeoutIfFarArrival(callback, milliseconds) { | ||
this.onCalled(milliseconds); | ||
setTimeout(() => { | ||
if (this.last_date < new Date()) | ||
callback(); | ||
}, milliseconds); | ||
} | ||
} | ||
exports.SetTimeouService = SetTimeouService; | ||
//# sourceMappingURL=SetTimeouService.js.map |
@@ -11,3 +11,3 @@ { | ||
"private": false, | ||
"version": "1.4.32", | ||
"version": "1.4.34", | ||
"author": "Amir Abolhasani", | ||
@@ -14,0 +14,0 @@ "license": "MIT", |
@@ -5,14 +5,30 @@ import { TimeOperation } from "./TimeOperation"; | ||
{ | ||
private last: Date = new Date(); | ||
private last_date: Date = new Date(); | ||
private last_index: number = 0; | ||
private onCalled(milliseconds: number) | ||
{ | ||
this.last_index++; | ||
let l = TimeOperation.millisecondsLater(milliseconds - 1, this.last_date); | ||
if (this.last_date < l) | ||
this.last_date = l; | ||
return this.last_index; | ||
} | ||
setTimeoutIfNotCalledAgain(callback: () => void, milliseconds: number) | ||
{ | ||
let l = TimeOperation.millisecondsLater(milliseconds - 1, this.last); | ||
if (this.last < l) | ||
this.last = l; | ||
let index = this.onCalled(milliseconds); | ||
setTimeout(() => | ||
{ | ||
if (this.last < new Date()) | ||
if (index === this.last_index) | ||
callback(); | ||
}, milliseconds); | ||
} | ||
setTimeoutIfFarArrival(callback: () => void, milliseconds: number) | ||
{ | ||
this.onCalled(milliseconds); | ||
setTimeout(() => | ||
{ | ||
if (this.last_date < new Date()) | ||
callback(); | ||
}, milliseconds); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
432332
5778