Permalink
Browse files

Better handling of backed up scheduled events

  • Loading branch information...
kriszyp committed Dec 8, 2010
1 parent b82d8a0 commit 4357c332b0e2a9e6a3ebdd4936ac14fade3cfa28
Showing with 13 additions and 5 deletions.
  1. +13 −5 engines/rhino/lib/delay.js
View
@@ -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 4357c33

Please sign in to comment.