diff --git a/lib/timers.js b/lib/timers.js index d0ec0c8d9da..a1a994c3ea7 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -131,7 +131,7 @@ function insert(item, msecs) { }; } - if (list._idleNext === list) { + if (isEmpty(list)) { // if empty (re)start the timer list.again(msecs); } @@ -142,16 +142,14 @@ function insert(item, msecs) { var unenroll = exports.unenroll = function(item) { - if (item._idleNext) { - remove(item); + remove(item); - var list = lists[item._idleTimeout]; - // if empty then stop the watcher - debug('unenroll'); - if (list && isEmpty(list)) { - debug('unenroll: list empty'); - list.stop(); - } + var list = lists[item._idleTimeout]; + // if empty then stop the watcher + debug('unenroll'); + if (list && isEmpty(list)) { + debug('unenroll: list empty'); + list.stop(); } }; @@ -166,6 +164,7 @@ exports.enroll = function(item, msecs) { init(item); }; + // call this whenever the item is active (not idle) // it will reset its timeout. exports.active = function(item) { diff --git a/test/simple/test-timers-linked-list.js b/test/simple/test-timers-linked-list.js index 9caa909d010..0d9a2b9b310 100644 --- a/test/simple/test-timers-linked-list.js +++ b/test/simple/test-timers-linked-list.js @@ -11,6 +11,11 @@ var D = { name: "D" }; L.init(list); +L.init(A); +L.init(B); +L.init(C); +L.init(D); + assert.ok(L.isEmpty(list)); assert.equal(null, L.peek(list));