mirror of
https://github.com/hanzoai/agency.git
synced 2026-11-02 19:13:28 +00:00
33 lines
770 B
Plaintext
33 lines
770 B
Plaintext
// src/removable.ts
|
|
import { timeoutManager } from "./timeoutManager.js";
|
|
import { isServer, isValidTimeout } from "./utils.js";
|
|
var Removable = class {
|
|
#gcTimeout;
|
|
destroy() {
|
|
this.clearGcTimeout();
|
|
}
|
|
scheduleGc() {
|
|
this.clearGcTimeout();
|
|
if (isValidTimeout(this.gcTime)) {
|
|
this.#gcTimeout = timeoutManager.setTimeout(() => {
|
|
this.optionalRemove();
|
|
}, this.gcTime);
|
|
}
|
|
}
|
|
updateGcTime(newGcTime) {
|
|
this.gcTime = Math.max(
|
|
this.gcTime || 0,
|
|
newGcTime ?? (isServer ? Infinity : 5 * 60 * 1e3)
|
|
);
|
|
}
|
|
clearGcTimeout() {
|
|
if (this.#gcTimeout) {
|
|
timeoutManager.clearTimeout(this.#gcTimeout);
|
|
this.#gcTimeout = void 0;
|
|
}
|
|
}
|
|
};
|
|
export {
|
|
Removable
|
|
};
|
|
//# sourceMappingURL=removable.js.map |