Skip to content

Instantly share code, notes, and snippets.

@fonzerelly
Created January 19, 2014 21:19
Show Gist options
  • Save fonzerelly/8511168 to your computer and use it in GitHub Desktop.
Save fonzerelly/8511168 to your computer and use it in GitHub Desktop.
var setTimeout,
clearTimeout,
setInterval,
clearInterval,
endAllTimers;
(function () {
var timer = new java.util.Timer();
var counter = 1;
var ids = {};
setTimeout = function (fn,delay) {
var id = counter += 1;
ids[id] = new JavaAdapter(java.util.TimerTask,{run: fn});
timer.schedule(ids[id],delay);
return id;
};
clearTimeout = function (id) {
ids[id].cancel();
timer.purge();
delete ids[id];
};
setInterval = function (fn,delay) {
var id = counter += 1;
ids[id] = new JavaAdapter(java.util.TimerTask,{run: fn});
timer.schedule(ids[id],delay,delay);
return id;
};
clearInterval = clearTimeout;
/*** added ***/
endAllTimers = function () {
timer.cancel();
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment