1 dump('entering util/exec.js\n');
3 if (typeof util == 'undefined') var util = {};
4 util.exec = function(chunk_size) {
7 this.chunk_size = chunk_size || 1;
8 obj.clear_timer = function() {
10 if (typeof obj.debug != 'undefined' && obj.debug) { dump('EXEC: Clearing interval with id = ' + obj._intervalId + '\n'); }
11 window.clearInterval(obj._intervalId);
13 alert('Error in clear_timer: ' + E);
20 util.exec.prototype = {
21 // This will create a timer that polls the specified array and shifts off functions to execute
22 'timer' : function(funcs,interval) {
25 if (obj._intervalId) {
27 window.removeEventListener('unload',obj.clear_timer,false);
29 var intervalId = window.setInterval(
31 if (typeof obj.debug != 'undefined' && obj.debug) { dump('EXEC: ' + location.pathname + ': Running interval with id = ' + intervalId + '\n'); }
32 var i = obj.chunk_size;
33 while (funcs.length > 0 && i > 0) {
39 obj._intervalId = intervalId;
40 window.addEventListener('unload',obj.clear_timer,false);
43 // This executes a series of functions, but tries to give other events/functions a chance to
44 // execute between each one.
45 'chain' : function () {
48 for (var i = 0; i < arguments.length; i++) {
49 var arg = arguments[i];
50 switch(arg.constructor.name) {
55 for (var j = 0; j < arg.length; j++) {
56 if (typeof arg[j] == 'function') args.push( arg[j] );
61 if (typeof arg[j] == 'function') args.push( arg[j] );
66 if (args.length > 0) setTimeout(
69 for (var i = 0; (i < args.length && i < obj.chunk_size) ; i++) {
71 if (typeof args[i] == 'function') {
72 dump('EXEC: executing queued function. intervalId = ' + obj._intervalId + '\n');
74 dump('EXEC: function = ' + args[i] + '\n');
78 alert('FIXME -- typeof args['+i+'] == ' + typeof args[i]);
81 dump('EXEC: util.exec.chain error: ' + js2JSON(E) + '\n');
82 var keep_going = false;
83 if (typeof obj.on_error == 'function') {
84 keep_going = obj.on_error(E);
87 if (typeof obj.debug != 'undefined' && obj.debug) { dump('EXEC: chain not broken\n'); }
89 if (args.length > 1 ) obj.chain( args.slice(1) );
92 if (typeof obj.debug != 'undefined' && obj.debug) { dump('EXEC: another error: ' + js2JSON(E) + '\n'); }
95 if (typeof obj.debug != 'undefined' && obj.debug) { dump('EXEC: chain broken\n'); }
100 if (args.length > obj.chunk_size ) obj.chain( args.slice(obj.chunk_size) );
109 dump('exiting util/exec.js\n');