// value = list
var lists = {};
+
+// call this whenever the item is active (not idle)
+// it will reset its timeout.
// the main function - creates lists on demand and the watchers associated
// with them.
-function insert(item, msecs) {
- item._idleStart = Timer.now();
- item._idleTimeout = msecs;
-
+exports.active = function(item) {
+ const msecs = item._idleTimeout;
if (msecs < 0) return;
+ item._idleStart = Timer.now();
+
var list;
if (lists[msecs]) {
L.append(list, item);
assert(!L.isEmpty(list)); // list is not empty
-}
+};
function listOnTimeout() {
var msecs = this.msecs;
};
-// call this whenever the item is active (not idle)
-// it will reset its timeout.
-exports.active = function(item) {
- var msecs = item._idleTimeout;
- if (msecs >= 0)
- insert(item, msecs);
-};
-
-
/*
* DOM-style timers
*/
--- /dev/null
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const active = require('timers').active;
+
+// active() should create timers for these
+var legitTimers = [
+ { _idleTimeout: 0 },
+ { _idleTimeout: 1 }
+];
+
+legitTimers.forEach(function(legit) {
+ const savedTimeout = legit._idleTimeout;
+ active(legit);
+ // active() should mutate these objects
+ assert(legit._idleTimeout === savedTimeout);
+ assert(Number.isInteger(legit._idleStart));
+ assert(legit._idleNext);
+ assert(legit._idlePrev);
+});
+
+
+// active() should not create a timer for these
+var bogusTimers = [
+ { _idleTimeout: -1 }
+];
+
+bogusTimers.forEach(function(bogus) {
+ const savedTimeout = bogus._idleTimeout;
+ active(bogus);
+ // active() should not mutate these objects
+ assert.deepStrictEqual(bogus, {_idleTimeout: savedTimeout});
+});