fix(core): update

This commit is contained in:
Philipp Kunz 2020-07-14 01:11:48 +00:00
parent 60587f052c
commit 979e93be27
2 changed files with 26 additions and 4 deletions

View File

@ -2,7 +2,13 @@ import * as plugins from './lik.plugins';
import { InterestMap, IInterestComparisonFunc } from './lik.interestmap'; import { InterestMap, IInterestComparisonFunc } from './lik.interestmap';
export interface IInterestOptions {
markLostAfterDefault: number;
}
export class Interest<DTInterestId, DTInterestFullfillment> { export class Interest<DTInterestId, DTInterestFullfillment> {
public options: IInterestOptions;
private interestMapRef: InterestMap<DTInterestId, DTInterestFullfillment>; private interestMapRef: InterestMap<DTInterestId, DTInterestFullfillment>;
public originalInterest: DTInterestId; public originalInterest: DTInterestId;
public comparisonFunc: IInterestComparisonFunc<DTInterestId>; public comparisonFunc: IInterestComparisonFunc<DTInterestId>;
@ -41,14 +47,20 @@ export class Interest<DTInterestId, DTInterestFullfillment> {
constructor( constructor(
interestMapArg: InterestMap<DTInterestId, DTInterestFullfillment>, interestMapArg: InterestMap<DTInterestId, DTInterestFullfillment>,
interestArg: DTInterestId, interestArg: DTInterestId,
comparisonFuncArg: IInterestComparisonFunc<DTInterestId> comparisonFuncArg: IInterestComparisonFunc<DTInterestId>,
optionsArg?: IInterestOptions
) { ) {
this.interestMapRef = interestMapArg;
this.originalInterest = interestArg; this.originalInterest = interestArg;
this.comparisonFunc = comparisonFuncArg; this.comparisonFunc = comparisonFuncArg;
this.interestMapRef = interestMapArg; this.options = optionsArg;
this.destructionTimer.completed.then(() => { this.destructionTimer.completed.then(() => {
this.destroy(); this.destroy();
}); });
if (this.options?.markLostAfterDefault) {
plugins.smartdelay.delayFor(this.options.markLostAfterDefault).then(this.markLost);
}
} }
// =============================== // ===============================

View File

@ -7,7 +7,13 @@ import { Interest } from './lik.interestmap.interest';
export type IInterestComparisonFunc<T> = (objectArg: T) => string; export type IInterestComparisonFunc<T> = (objectArg: T) => string;
export interface IInterestMapOptions {
markLostAfterDefault?: number;
}
export class InterestMap<DTInterestId, DTInterestFullfillment> { export class InterestMap<DTInterestId, DTInterestFullfillment> {
public options: IInterestMapOptions;
/** /**
* stores interests that are currently fullfilled by the cache * stores interests that are currently fullfilled by the cache
*/ */
@ -18,8 +24,9 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
*/ */
private comparisonFunc: IInterestComparisonFunc<DTInterestId>; private comparisonFunc: IInterestComparisonFunc<DTInterestId>;
constructor(comparisonFuncArg: IInterestComparisonFunc<DTInterestId>) { constructor(comparisonFuncArg: IInterestComparisonFunc<DTInterestId>, optionsArg: IInterestMapOptions = {}) {
this.comparisonFunc = comparisonFuncArg; this.comparisonFunc = comparisonFuncArg;
this.options = optionsArg;
} }
/** /**
@ -34,7 +41,10 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
const newInterest = new Interest<DTInterestId, DTInterestFullfillment>( const newInterest = new Interest<DTInterestId, DTInterestFullfillment>(
this, this,
objectArg, objectArg,
this.comparisonFunc this.comparisonFunc,
{
markLostAfterDefault: this.options.markLostAfterDefault
}
); );
let interestExists = false; let interestExists = false;
await this.interestObjectMap.forEach((interestArg) => { await this.interestObjectMap.forEach((interestArg) => {