Skip to content

Commit

Permalink
fixup: keep trigger timers in their own map
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott committed Sep 26, 2015
1 parent e1ccbad commit 9f28c3c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const TIMEOUT_MAX = 2147483647; // 2^31-1
// key = time in milliseconds
// value = set
var lists = {};
var triggerTimers = new Map();

// the main function - creates lists on demand and the watchers associated
// with them.
Expand All @@ -37,7 +38,7 @@ function insert(item, msecs) {
timer[kOnTimeout] = listOnTimeout;

lists[msecs] = new Set();
lists[msecs].timer = timer;
triggerTimers.set(msecs, timer);
}

lists[msecs].add(item);
Expand Down Expand Up @@ -114,8 +115,9 @@ const unenroll = exports.unenroll = function(item) {

// if empty then stop the watcher
if (list && list.size === 0) {
if (list.timer) {
list.timer.close();
if (triggerTimers.has(item._idleTimeout)) {
triggerTimers.get(item._idleTimeout).close();
triggerTimers.delete(item._idleTimeout);
}
delete lists[item._idleTimeout];
}
Expand Down

0 comments on commit 9f28c3c

Please sign in to comment.