From 28d33ca3b57017d5879e01105a1ddfeab5ee8911 Mon Sep 17 00:00:00 2001 From: Nick Galbreath Date: Thu, 29 Apr 2010 01:50:34 +0000 Subject: [PATCH] untabify only. Will make next commit nicer --- src/timer/timer.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/timer/timer.js b/src/timer/timer.js index 5b12326e..83b8405d 100644 --- a/src/timer/timer.js +++ b/src/timer/timer.js @@ -1,12 +1,12 @@ /* -* timer.js +* timer.js * implementation provided by Steven Parkes */ //private var $timers = [], EVENT_LOOP_RUNNING = false; - + $timers.lock = function(fn){ Envjs.sync(fn)(); }; @@ -17,9 +17,9 @@ var Timer = function(fn, interval){ this.interval = interval; this.at = Date.now() + interval; // allows for calling wait() from callbacks - this.running = false; + this.running = false; }; - + Timer.prototype.start = function(){}; Timer.prototype.stop = function(){}; @@ -29,15 +29,15 @@ Timer.normalize = function(time) { if ( isNaN(time) || time < 0 ) { time = 0; } - + if ( EVENT_LOOP_RUNNING && time < Timer.MIN_TIME ) { time = Timer.MIN_TIME; } return time; }; -// html5 says this should be at least 4, but the parser is using +// html5 says this should be at least 4, but the parser is using // a setTimeout for the SAX stuff which messes up the world -Timer.MIN_TIME = /* 4 */ 0; +Timer.MIN_TIME = /* 4 */ 0; /** * @function setTimeout @@ -90,10 +90,10 @@ setInterval = function(fn, time){ time = 10; } if (typeof fn == 'string') { - var fnstr = fn; - fn = function() { + var fnstr = fn; + fn = function() { eval(fnstr); - }; + }; } var num; $timers.lock(function(){ @@ -117,15 +117,15 @@ clearInterval = clearTimeout = function(num){ delete $timers[num]; } }); -}; +}; -// wait === null/undefined: execute any timers as they fire, +// wait === null/undefined: execute any timers as they fire, // waiting until there are none left -// wait(n) (n > 0): execute any timers as they fire until there -// are none left waiting at least n ms but no more, even if there +// wait(n) (n > 0): execute any timers as they fire until there +// are none left waiting at least n ms but no more, even if there // are future events/current threads // wait(0): execute any immediately runnable timers and return -// wait(-n): keep sleeping until the next event is more than n ms +// wait(-n): keep sleeping until the next event is more than n ms // in the future // // TODO: make a priority queue ... @@ -135,16 +135,16 @@ Envjs.wait = function(wait) { var delta_wait, start = Date.now(), was_running = EVENT_LOOP_RUNNING; - + if (wait < 0) { delta_wait = -wait; wait = 0; } - EVENT_LOOP_RUNNING = true; + EVENT_LOOP_RUNNING = true; if (wait !== 0 && wait !== null && wait !== undefined){ wait += Date.now(); } - + var earliest, timer, sleep, @@ -152,7 +152,7 @@ Envjs.wait = function(wait) { goal, now, nextfn; - + for (;;) { //console.log('timer loop'); earliest = sleep = goal = now = nextfn = null; @@ -196,7 +196,7 @@ Envjs.wait = function(wait) { if ( !earliest ) { // no events in the queue (but maybe XHR will bring in events, so ... if ( !wait || wait < Date.now() ) { - // Loop ends if there are no events and a wait hasn't been + // Loop ends if there are no events and a wait hasn't been // requested or has expired break; } @@ -204,11 +204,11 @@ Envjs.wait = function(wait) { } else { // there are events in the queue, but they aren't firable now /*if ( delta_wait && sleep <= delta_wait ) { - //TODO: why waste a check on a tight + //TODO: why waste a check on a tight // loop if it just falls through? // if they will happen within the next delta, fall through to sleep } else */if ( wait === 0 || ( wait > 0 && wait < Date.now () ) ) { - // loop ends even if there are events but the user + // loop ends even if there are events but the user // specifcally asked not to wait too long break; } @@ -222,7 +222,7 @@ Envjs.wait = function(wait) { } //console.log('sleeping %s', sleep); Envjs.sleep(sleep); - + } EVENT_LOOP_RUNNING = was_running; };