diff --git a/ts/lik.interestmap.interest.ts b/ts/lik.interestmap.interest.ts index aec2ff2..33b34b7 100644 --- a/ts/lik.interestmap.interest.ts +++ b/ts/lik.interestmap.interest.ts @@ -2,7 +2,13 @@ import * as plugins from './lik.plugins'; import { InterestMap, IInterestComparisonFunc } from './lik.interestmap'; +export interface IInterestOptions { + markLostAfterDefault: number; +} + export class Interest { + public options: IInterestOptions; + private interestMapRef: InterestMap; public originalInterest: DTInterestId; public comparisonFunc: IInterestComparisonFunc; @@ -41,14 +47,20 @@ export class Interest { constructor( interestMapArg: InterestMap, interestArg: DTInterestId, - comparisonFuncArg: IInterestComparisonFunc + comparisonFuncArg: IInterestComparisonFunc, + optionsArg?: IInterestOptions ) { + this.interestMapRef = interestMapArg; this.originalInterest = interestArg; this.comparisonFunc = comparisonFuncArg; - this.interestMapRef = interestMapArg; + this.options = optionsArg; + this.destructionTimer.completed.then(() => { this.destroy(); }); + if (this.options?.markLostAfterDefault) { + plugins.smartdelay.delayFor(this.options.markLostAfterDefault).then(this.markLost); + } } // =============================== diff --git a/ts/lik.interestmap.ts b/ts/lik.interestmap.ts index a4462a7..cde243c 100644 --- a/ts/lik.interestmap.ts +++ b/ts/lik.interestmap.ts @@ -7,7 +7,13 @@ import { Interest } from './lik.interestmap.interest'; export type IInterestComparisonFunc = (objectArg: T) => string; +export interface IInterestMapOptions { + markLostAfterDefault?: number; +} + export class InterestMap { + public options: IInterestMapOptions; + /** * stores interests that are currently fullfilled by the cache */ @@ -18,8 +24,9 @@ export class InterestMap { */ private comparisonFunc: IInterestComparisonFunc; - constructor(comparisonFuncArg: IInterestComparisonFunc) { + constructor(comparisonFuncArg: IInterestComparisonFunc, optionsArg: IInterestMapOptions = {}) { this.comparisonFunc = comparisonFuncArg; + this.options = optionsArg; } /** @@ -34,7 +41,10 @@ export class InterestMap { const newInterest = new Interest( this, objectArg, - this.comparisonFunc + this.comparisonFunc, + { + markLostAfterDefault: this.options.markLostAfterDefault + } ); let interestExists = false; await this.interestObjectMap.forEach((interestArg) => {