| 59 | } |
| 60 | |
| 61 | _scheduleCleanup(delay: number) { |
| 62 | this._cleanupTimer = setTimeout(async () => { |
| 63 | try { |
| 64 | await this._cleanup(); |
| 65 | } catch (err) { |
| 66 | logger.error('Session cleanup error:', err); |
| 67 | } |
| 68 | // Schedule the next run only after this one completes. |
| 69 | this._scheduleCleanup(CLEANUP_INTERVAL_MS); |
| 70 | }, delay); |
| 71 | // Don't prevent Node.js from exiting. |
| 72 | if (this._cleanupTimer.unref) this._cleanupTimer.unref(); |
| 73 | } |
| 74 | |
| 75 | shutdown() { |
| 76 | for (const {timeout} of this._expirations.values()) clearTimeout(timeout); |