A few more list clean ups

This commit is contained in:
Ryan Dahl 2011-01-13 02:22:09 -08:00
parent 09994438e5
commit 29f48d48e5
2 changed files with 14 additions and 10 deletions

View File

@ -131,7 +131,7 @@ function insert(item, msecs) {
}; };
} }
if (list._idleNext === list) { if (isEmpty(list)) {
// if empty (re)start the timer // if empty (re)start the timer
list.again(msecs); list.again(msecs);
} }
@ -142,16 +142,14 @@ function insert(item, msecs) {
var unenroll = exports.unenroll = function(item) { var unenroll = exports.unenroll = function(item) {
if (item._idleNext) { remove(item);
remove(item);
var list = lists[item._idleTimeout]; var list = lists[item._idleTimeout];
// if empty then stop the watcher // if empty then stop the watcher
debug('unenroll'); debug('unenroll');
if (list && isEmpty(list)) { if (list && isEmpty(list)) {
debug('unenroll: list empty'); debug('unenroll: list empty');
list.stop(); list.stop();
}
} }
}; };
@ -166,6 +164,7 @@ exports.enroll = function(item, msecs) {
init(item); init(item);
}; };
// call this whenever the item is active (not idle) // call this whenever the item is active (not idle)
// it will reset its timeout. // it will reset its timeout.
exports.active = function(item) { exports.active = function(item) {

View File

@ -11,6 +11,11 @@ var D = { name: "D" };
L.init(list); L.init(list);
L.init(A);
L.init(B);
L.init(C);
L.init(D);
assert.ok(L.isEmpty(list)); assert.ok(L.isEmpty(list));
assert.equal(null, L.peek(list)); assert.equal(null, L.peek(list));