Skip to content

Commit

Permalink
fix(max-age): unref timeouts to not block processes from exiting
Browse files Browse the repository at this point in the history
Fix #25
  • Loading branch information
medikoo committed Feb 23, 2018
1 parent ad0f1f4 commit 5bcc5a4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ext/max-age.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ 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]);
}
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]);
Expand Down

0 comments on commit 5bcc5a4

Please sign in to comment.