@@ -5,12 +5,14 @@ var assert = process.assert;
55 * To enable debug statements for the timers do NODE_DEBUG=8 ./node script.js
66 */
77var debugLevel = parseInt ( process . env . NODE_DEBUG , 16 ) ;
8- function debug ( ) {
9- if ( debugLevel & 0x8 ) {
10- require ( 'util' ) . error . apply ( this , arguments ) ;
11- }
8+ var debug ;
9+ if ( debugLevel & 0x8 ) {
10+ debug = function ( ) { require ( 'util' ) . error . apply ( this , arguments ) ; } ;
11+ } else {
12+ debug = function ( ) { } ;
1213}
1314
15+
1416// IDLE TIMEOUTS
1517//
1618// Because often many sockets will have the same idle timeout we will not
@@ -25,29 +27,29 @@ function debug () {
2527var lists = { } ;
2628
2729// show the most idle item
28- function peek ( list ) {
30+ function peek ( list ) {
2931 if ( list . _idlePrev == list ) return null ;
3032 return list . _idlePrev ;
3133}
3234
3335
3436// remove the most idle item from the list
35- function shift ( list ) {
37+ function shift ( list ) {
3638 var first = list . _idlePrev ;
3739 remove ( first ) ;
3840 return first ;
3941}
4042
4143
4244// remove a item from its list
43- function remove ( item ) {
45+ function remove ( item ) {
4446 item . _idleNext . _idlePrev = item . _idlePrev ;
4547 item . _idlePrev . _idleNext = item . _idleNext ;
4648}
4749
4850
4951// remove a item from its list and place at the end.
50- function append ( list , item ) {
52+ function append ( list , item ) {
5153 item . _idleNext = list . _idleNext ;
5254 list . _idleNext . _idlePrev = item ;
5355 item . _idlePrev = list ;
@@ -57,7 +59,7 @@ function append (list, item) {
5759
5860// the main function - creates lists on demand and the watchers associated
5961// with them.
60- function insert ( item , msecs ) {
62+ function insert ( item , msecs ) {
6163 item . _idleStart = new Date ( ) ;
6264 item . _idleTimeout = msecs ;
6365
@@ -74,18 +76,18 @@ function insert (item, msecs) {
7476
7577 lists [ msecs ] = list ;
7678
77- list . callback = function ( ) {
79+ list . callback = function ( ) {
7880 debug ( 'timeout callback ' + msecs ) ;
7981 // TODO - don't stop and start the watcher all the time.
8082 // just set its repeat
8183 var now = new Date ( ) ;
82- debug ( " now: " + now ) ;
84+ debug ( ' now: ' + now ) ;
8385 var first ;
8486 while ( first = peek ( list ) ) {
8587 var diff = now - first . _idleStart ;
8688 if ( diff < msecs ) {
8789 list . again ( msecs - diff ) ;
88- debug ( msecs + ' list wait because diff is ' + diff ) ;
90+ debug ( msecs + ' list wait because diff is ' + diff ) ;
8991 return ;
9092 } else {
9193 remove ( first ) ;
@@ -109,7 +111,7 @@ function insert (item, msecs) {
109111}
110112
111113
112- var unenroll = exports . unenroll = function ( item ) {
114+ var unenroll = exports . unenroll = function ( item ) {
113115 if ( item . _idleNext ) {
114116 remove ( item ) ;
115117
@@ -125,7 +127,7 @@ var unenroll = exports.unenroll = function (item) {
125127
126128
127129// Does not start the time, just sets up the members needed.
128- exports . enroll = function ( item , msecs ) {
130+ exports . enroll = function ( item , msecs ) {
129131 // if this item was already in a list somewhere
130132 // then we should unenroll it from that
131133 if ( item . _idleNext ) unenroll ( item ) ;
@@ -137,7 +139,7 @@ exports.enroll = function (item, msecs) {
137139
138140// call this whenever the item is active (not idle)
139141// it will reset its timeout.
140- exports . active = function ( item ) {
142+ exports . active = function ( item ) {
141143 var msecs = item . _idleTimeout ;
142144 if ( msecs >= 0 ) {
143145 var list = lists [ msecs ] ;
@@ -162,8 +164,8 @@ exports.active = function (item) {
162164 */
163165
164166
165- exports . setTimeout = function ( callback , after ) {
166- var timer ;
167+ exports . setTimeout = function ( callback , after ) {
168+ var timer ;
167169
168170 if ( after <= 0 ) {
169171 // Use the slow case for after == 0
@@ -186,7 +188,7 @@ exports.setTimeout = function (callback, after) {
186188 */
187189 if ( arguments . length > 2 ) {
188190 var args = Array . prototype . slice . call ( arguments , 2 ) ;
189- var c = function ( ) {
191+ var c = function ( ) {
190192 callback . apply ( timer , args ) ;
191193 } ;
192194
@@ -207,7 +209,7 @@ exports.setTimeout = function (callback, after) {
207209} ;
208210
209211
210- exports . clearTimeout = function ( timer ) {
212+ exports . clearTimeout = function ( timer ) {
211213 if ( timer && ( timer . callback || timer . _onTimeout ) ) {
212214 timer . callback = timer . _onTimeout = null ;
213215 exports . unenroll ( timer ) ;
@@ -216,12 +218,12 @@ exports.clearTimeout = function (timer) {
216218} ;
217219
218220
219- exports . setInterval = function ( callback , repeat ) {
221+ exports . setInterval = function ( callback , repeat ) {
220222 var timer = new Timer ( ) ;
221223
222224 if ( arguments . length > 2 ) {
223225 var args = Array . prototype . slice . call ( arguments , 2 ) ;
224- timer . callback = function ( ) {
226+ timer . callback = function ( ) {
225227 callback . apply ( timer , args ) ;
226228 } ;
227229 } else {
@@ -233,7 +235,7 @@ exports.setInterval = function (callback, repeat) {
233235} ;
234236
235237
236- exports . clearInterval = function ( timer ) {
238+ exports . clearInterval = function ( timer ) {
237239 if ( timer instanceof Timer ) {
238240 timer . callback = null ;
239241 timer . stop ( ) ;
0 commit comments