Browse files

Don't enqueue callback if backed up

  • Loading branch information...
1 parent dc3f6b3 commit cdd6b414775440cd93da5d6c8f6f9802821c043b @kriszyp committed Dec 1, 2010
Showing with 13 additions and 5 deletions.
  1. +13 −5 lib/nodules-utils/rhino-delay.js
View
18 lib/nodules-utils/rhino-delay.js
@@ -47,13 +47,21 @@ var _scheduleTimeout = function(callback, delay, repeat)
timer = timer || new java.util.Timer("JavaScript timer thread", true);
queue = queue || require("event-loop");
+ var lastFinished = true;
var task = timeout.task = new java.util.TimerTask({
run: function(){
- queue.enqueue(function(){
- if(!timeout.cancelled){ // check to make sure it wasn't enqueued and then later cancelled
- func();
- }
- });
+ if(lastFinished){
+ lastFinished = false;
+ queue.enqueue(function(){
+ if(!timeout.cancelled){ // check to make sure it wasn't enqueued and then later cancelled
+ try{
+ func();
+ }finally{
+ lastFinished = true;
+ }
+ }
+ });
+ }
}
});
delay = Math.floor(delay);

0 comments on commit cdd6b41

Please sign in to comment.