Skip to content

Commit

Permalink
simpler solution to jsdoc#257
Browse files Browse the repository at this point in the history
keeping env.run.finish in case we add more logging at some point
  • Loading branch information
hegemonic committed Nov 11, 2012
1 parent 1a7a7f8 commit ef6d78f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
20 changes: 9 additions & 11 deletions jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,18 +423,16 @@ function main() {
}
}

try { main(); }
catch(e) {
if (e.rhinoException != null) {
e.rhinoException.printStackTrace();
} else {
throw e;
}
try {
main();
env.run.finish = new Date();
process.exit(0);
}
finally {
catch(e) {
env.run.finish = new Date();
// on Rhino, we never exit unless we shut down the timer pool
if (__timerPool) {
__timerPool.shutdownNow();
if (e.rhinoException != null) {
e.rhinoException.printStackTrace();
} else {
throw e;
}
}
10 changes: 4 additions & 6 deletions lib/rhino-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ __dirname = env.dirname;
* @see https://developer.mozilla.org/en-US/docs/DOM/window#Methods
*/

__timerPool = null;

setTimeout = null,
clearTimeout = null,
setInterval = null,
clearInterval = null;

(function() {
// TODO: tune number of threads if necessary
__timerPool = new java.util.concurrent.ScheduledThreadPoolExecutor(10);
var timerPool = new java.util.concurrent.ScheduledThreadPoolExecutor(10);
var timers = {};
var timerCount = 1;
var timerUnits = java.util.concurrent.TimeUnit.MILLISECONDS;
Expand All @@ -39,21 +37,21 @@ clearInterval = null;
setTimeout = function(fn, delay) {
var timerId = timerCount++;
var callback = getCallback(fn);
timers[timerId] = __timerPool.schedule(callback, delay, timerUnits);
timers[timerId] = timerPool.schedule(callback, delay, timerUnits);
return timerId;
};

clearTimeout = function(timerId) {
if (timers[timerId]) {
__timerPool.remove(timers[timerId]);
timerPool.remove(timers[timerId]);
delete timers[timerId];
}
};

setInterval = function(fn, delay) {
var timerId = timerCount++;
var callback = getCallback(fn);
timers[timerId] = __timerPool.scheduleAtFixedRate(callback, delay, delay, timerUnits);
timers[timerId] = timerPool.scheduleAtFixedRate(callback, delay, delay, timerUnits);
return timerId;
};

Expand Down

0 comments on commit ef6d78f

Please sign in to comment.