Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…onously when timeout is set to zero
  • Loading branch information
orslumen committed Apr 8, 2011
1 parent 18d271d commit fe499c2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions envjs/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,22 @@ Envjs.once('tick', function(){
* @param {Object} time
*/
exports.setTimeout = setTimeout = function(fn, time){
log.debug('setTimeout %s', time);
return Envjs.timers.addTimerOrInterval(fn, time, 'timeout');
log.debug('setTimeout %s', time);
if (time === 0) {
fn.apply(fn,[]);
return -1;
} else {
return Envjs.timers.addTimerOrInterval(fn, time, 'timeout');
}
};

/**
* clearTimeout
* @param {Object} id
*/
exports.clearTimeout = clearTimeout = function(id){
log.debug('clearTimeout %s', id);
return Envjs.timers.removeTimerOrInterval(id, 'timeout');
exports.clearTimeout = clearTimeout = function(id){
log.debug('clearTimeout %s', id);
return id === -1 ? null : Envjs.timers.removeTimerOrInterval(id, 'timeout');
};

/**
Expand Down

0 comments on commit fe499c2

Please sign in to comment.