| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8dfdee3 commit 63644dd
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,14 +23,17 @@ const TIMEOUT_MAX = 2147483647; // 2^31-1 | |||
| 23 | 23 | // value = list | |
| 24 | 24 | var lists = {}; | |
| 25 | 25 | ||
| 26 | + | ||
| 27 | + // call this whenever the item is active (not idle) | ||
| 28 | + // it will reset its timeout. | ||
| 26 | 29 | // the main function - creates lists on demand and the watchers associated | |
| 27 | 30 | // with them. | |
| 28 | - function insert(item, msecs) { | ||
| 29 | - item._idleStart = Timer.now(); | ||
| 30 | - item._idleTimeout = msecs; | ||
| 31 | - | ||
| 31 | + exports.active = function(item) { | ||
| 32 | + const msecs = item._idleTimeout; | ||
| 32 | 33 | if (msecs < 0) return; | |
| 33 | 34 | ||
| 35 | + item._idleStart = Timer.now(); | ||
| 36 | + | ||
| 34 | 37 | var list; | |
| 35 | 38 | ||
| 36 | 39 | if (lists[msecs]) { | |
@@ -48,7 +51,7 @@ function insert(item, msecs) { | |||
| 48 | 51 | ||
| 49 | 52 | L.append(list, item); | |
| 50 | 53 | assert(!L.isEmpty(list)); // list is not empty | |
| 51 | - } | ||
| 54 | + }; | ||
| 52 | 55 | ||
| 53 | 56 | function listOnTimeout() { | |
| 54 | 57 | var msecs = this.msecs; | |
@@ -156,15 +159,6 @@ exports.enroll = function(item, msecs) { | |||
| 156 | 159 | }; | |
| 157 | 160 | ||
| 158 | 161 | ||
| 159 | - // call this whenever the item is active (not idle) | ||
| 160 | - // it will reset its timeout. | ||
| 161 | - exports.active = function(item) { | ||
| 162 | - var msecs = item._idleTimeout; | ||
| 163 | - if (msecs >= 0) | ||
| 164 | - insert(item, msecs); | ||
| 165 | - }; | ||
| 166 | - | ||
| 167 | - | ||
| 168 | 162 | /* | |
| 169 | 163 | * DOM-style timers | |
| 170 | 164 | */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const active = require('timers').active; | ||
| 5 | + | ||
| 6 | + // active() should create timers for these | ||
| 7 | + var legitTimers = [ | ||
| 8 | + { _idleTimeout: 0 }, | ||
| 9 | + { _idleTimeout: 1 } | ||
| 10 | + ]; | ||
| 11 | + | ||
| 12 | + legitTimers.forEach(function(legit) { | ||
| 13 | + const savedTimeout = legit._idleTimeout; | ||
| 14 | + active(legit); | ||
| 15 | + // active() should mutate these objects | ||
| 16 | + assert(legit._idleTimeout === savedTimeout); | ||
| 17 | + assert(Number.isInteger(legit._idleStart)); | ||
| 18 | + assert(legit._idleNext); | ||
| 19 | + assert(legit._idlePrev); | ||
| 20 | + }); | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + // active() should not create a timer for these | ||
| 24 | + var bogusTimers = [ | ||
| 25 | + { _idleTimeout: -1 } | ||
| 26 | + ]; | ||
| 27 | + | ||
| 28 | + bogusTimers.forEach(function(bogus) { | ||
| 29 | + const savedTimeout = bogus._idleTimeout; | ||
| 30 | + active(bogus); | ||
| 31 | + // active() should not mutate these objects | ||
| 32 | + assert.deepStrictEqual(bogus, {_idleTimeout: savedTimeout}); | ||
| 33 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments