fix: Updated WrappedExpiringStorage to use timer.unref

* fix: updated WrappedExpiringStorage tests and timer.unref calls

* fix: removed finalizable configs and inheritors that only used timer

* fix: updated test function to test setSafeInterval and timer.unref
This commit is contained in:
zg009
2023-03-13 02:30:42 -05:00
committed by GitHub
parent 63fd062f16
commit b6faed0db3
5 changed files with 12 additions and 68 deletions

View File

@@ -1,4 +1,3 @@
import type { Finalizable } from '../../init/final/Finalizable';
import { getLoggerFor } from '../../logging/LogUtil';
import { InternalServerError } from '../../util/errors/InternalServerError';
import { setSafeInterval } from '../../util/TimerUtil';
@@ -13,7 +12,7 @@ export type Expires<T> = { expires?: string; payload: T };
* Will delete expired entries when trying to get their value.
* Has a timer that will delete all expired data every hour (default value).
*/
export class WrappedExpiringStorage<TKey, TValue> implements ExpiringStorage<TKey, TValue>, Finalizable {
export class WrappedExpiringStorage<TKey, TValue> implements ExpiringStorage<TKey, TValue> {
protected readonly logger = getLoggerFor(this);
private readonly source: KeyValueStorage<TKey, Expires<TValue>>;
private readonly timer: NodeJS.Timeout;
@@ -28,6 +27,7 @@ export class WrappedExpiringStorage<TKey, TValue> implements ExpiringStorage<TKe
'Failed to remove expired entries',
this.removeExpiredEntries.bind(this),
timeout * 60 * 1000);
this.timer.unref();
}
public async get(key: TKey): Promise<TValue | undefined> {
@@ -121,11 +121,4 @@ export class WrappedExpiringStorage<TKey, TValue> implements ExpiringStorage<TKe
}
return result;
}
/**
* Stops the continuous cleanup timer.
*/
public async finalize(): Promise<void> {
clearInterval(this.timer);
}
}