From 5bcc5a4fad7031680b9803a2c3d1b9615ae47d33 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Fri, 23 Feb 2018 16:41:34 +0100 Subject: [PATCH] fix(max-age): unref timeouts to not block processes from exiting Fix #25 --- ext/max-age.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ext/max-age.js b/ext/max-age.js index 221fa41..4564857 100644 --- a/ext/max-age.js +++ b/ext/max-age.js @@ -22,12 +22,13 @@ extensions.maxAge = function (maxAge, conf, options) { timeouts = create(null); postfix = (options.async && extensions.async) || (options.promise && extensions.promise) - ? "async" - : ""; + ? "async" + : ""; conf.on("set" + postfix, function (id) { timeouts[id] = setTimeout(function () { conf.delete(id); }, maxAge); + if (typeof timeouts[id].unref === "function") timeouts[id].unref(); if (!preFetchTimeouts) return; if (preFetchTimeouts[id]) { if (preFetchTimeouts[id] !== "nextTick") clearTimeout(preFetchTimeouts[id]); @@ -35,6 +36,7 @@ extensions.maxAge = function (maxAge, conf, options) { preFetchTimeouts[id] = setTimeout(function () { delete preFetchTimeouts[id]; }, preFetchAge); + if (typeof preFetchTimeouts[id].unref === "function") preFetchTimeouts[id].unref(); }); conf.on("delete" + postfix, function (id) { clearTimeout(timeouts[id]);