Skip to content

Commit

Permalink
cachable - unref check interval to allow node exit (#919)
Browse files Browse the repository at this point in the history
When a check interval is passed to the cache, cachable starts an
interval that prevents node from exiting unless it gets cleared. There
is a public method to stop the interval, but it's flagged as internal
use only.

Given this, I've opted to unref the interval to allow the node process
to exit cleanly.

The other alternative would be to add a public close/disconnect API
method -- the Keyv interface seems to account for this case -- however,
it does make the API more cumbersome for the end-user.

Co-authored-by: Jared Wray <[email protected]>
  • Loading branch information
mothershipper and jaredwray authored Dec 3, 2024
1 parent 43de148 commit 18c4d47
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/cacheable/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,15 @@ export class CacheableMemory extends Hookified {
*/
public startIntervalCheck() {
if (this._checkInterval > 0) {
if (this._interval) {
// Be overly cautious and clear the interval as we've unref'd it
// and we don't want to leak it
clearInterval(this._interval);
}

this._interval = setInterval(() => {
this.checkExpiration();
}, this._checkInterval);
}, this._checkInterval).unref();
}
}

Expand Down

0 comments on commit 18c4d47

Please sign in to comment.