namirasoft-core
Advanced tools
Comparing version 1.4.44 to 1.4.45
@@ -8,2 +8,3 @@ import { IStorage } from "./IStorage"; | ||
private getFromSource; | ||
onExpired?: () => void; | ||
constructor(name: string, storage: IStorage, duration_minutes: number, getVersion: () => Promise<string>, getFromSource: () => Promise<DataType>); | ||
@@ -10,0 +11,0 @@ get(): Promise<DataType>; |
@@ -44,2 +44,11 @@ "use strict"; | ||
this.storage.set(this.name, value); | ||
if (this.onExpired) { | ||
let sleep = expires_at.getTime() - new Date().getTime(); | ||
if (sleep <= 0) | ||
sleep = 5 * 1000; | ||
setTimeout(() => { | ||
var _a; | ||
(_a = this.onExpired) === null || _a === void 0 ? void 0 : _a.call(this); | ||
}, sleep); | ||
} | ||
}); | ||
@@ -46,0 +55,0 @@ } |
@@ -11,3 +11,3 @@ { | ||
"private": false, | ||
"version": "1.4.44", | ||
"version": "1.4.45", | ||
"author": "Amir Abolhasani", | ||
@@ -14,0 +14,0 @@ "license": "MIT", |
@@ -17,3 +17,3 @@ import { IStorage } from "./IStorage"; | ||
private getFromSource: () => Promise<DataType>; | ||
// private onExpired: () => void; | ||
public onExpired?: () => void; | ||
constructor(name: string, storage: IStorage, duration_minutes: number, getVersion: () => Promise<string>, getFromSource: () => Promise<DataType>) | ||
@@ -26,3 +26,2 @@ { | ||
this.getFromSource = getFromSource; | ||
// this.onExpired = onExpired; | ||
} | ||
@@ -52,11 +51,13 @@ async get(): Promise<DataType> | ||
this.storage.set(this.name, value); | ||
// | ||
// let sleep = expires_at.getTime() - new Date().getTime(); | ||
// if (sleep <= 0) | ||
// sleep = 5 * 1000; | ||
// setTimeout(() => | ||
// { | ||
// if (this.onExpired) | ||
// this.onExpired(); | ||
// }, sleep); | ||
if (this.onExpired) | ||
{ | ||
let sleep = expires_at.getTime() - new Date().getTime(); | ||
if (sleep <= 0) | ||
sleep = 5 * 1000; | ||
setTimeout(() => | ||
{ | ||
this.onExpired?.(); | ||
}, sleep); | ||
} | ||
} | ||
@@ -63,0 +64,0 @@ del() |
Sorry, the diff of this file is not supported yet
435283
5814