summaryrefslogtreecommitdiff
path: root/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/scheduler.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/scaladoc/scala/tools/nsc/doc/html/resource/lib/scheduler.js')
-rw-r--r--src/scaladoc/scala/tools/nsc/doc/html/resource/lib/scheduler.js65
1 files changed, 51 insertions, 14 deletions
diff --git a/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/scheduler.js b/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/scheduler.js
index 4417f5b438..eb396bb5d3 100644
--- a/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/scheduler.js
+++ b/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/scheduler.js
@@ -1,44 +1,50 @@
// © 2010 EPFL/LAMP
-// code by Gilles Dubochet
+// code by Gilles Dubochet, Felix Mulder
function Scheduler() {
var scheduler = this;
var resolution = 0;
this.timeout = undefined;
- this.queues = new Array(0); // an array of work pacakges indexed by index in the labels table.
+ this.queues = new Array(0); // an array of work packages indexed by index in the labels table.
this.labels = new Array(0); // an indexed array of labels indexed by priority. This should be short.
+
this.label = function(name, priority) {
this.name = name;
this.priority = priority;
}
+
this.work = function(fn, self, args) {
this.fn = fn;
this.self = self;
this.args = args;
}
+
this.addLabel = function(name, priority) {
var idx = 0;
while (idx < scheduler.queues.length && scheduler.labels[idx].priority <= priority) { idx = idx + 1; }
scheduler.labels.splice(idx, 0, new scheduler.label(name, priority));
scheduler.queues.splice(idx, 0, new Array(0));
}
+
this.clearLabel = function(name) {
- var idx = 0;
- while (idx < scheduler.queues.length && scheduler.labels[idx].name != name) { idx = idx + 1; }
- if (idx < scheduler.queues.length && scheduler.labels[i].name == name) {
+ var idx = scheduler.indexOf(name);
+ if (idx != -1) {
scheduler.labels.splice(idx, 1);
scheduler.queues.splice(idx, 1);
}
}
+
this.nextWork = function() {
var fn = undefined;
var idx = 0;
while (idx < scheduler.queues.length && scheduler.queues[idx].length == 0) { idx = idx + 1; }
- if (idx < scheduler.queues.length && scheduler.queues[idx].length > 0) {
+
+ if (idx < scheduler.queues.length && scheduler.queues[idx].length > 0)
var fn = scheduler.queues[idx].shift();
- }
+
return fn;
}
+
this.add = function(labelName, fn, self, args) {
var doWork = function() {
scheduler.timeout = setTimeout(function() {
@@ -53,19 +59,50 @@ function Scheduler() {
}
}, resolution);
}
- var idx = 0;
- while (idx < scheduler.labels.length && scheduler.labels[idx].name != labelName) { idx = idx + 1; }
- if (idx < scheduler.queues.length && scheduler.labels[idx].name == labelName) {
+
+ var idx = scheduler.indexOf(labelName)
+ if (idx != -1) {
scheduler.queues[idx].push(new scheduler.work(fn, self, args));
if (scheduler.timeout == undefined) doWork();
+ } else {
+ throw("queue for add is non-existent");
}
- else throw("queue for add is non existant");
}
+
this.clear = function(labelName) {
+ scheduler.queues[scheduler.indexOf(labelName)] = new Array();
+ }
+
+ this.indexOf = function(label) {
var idx = 0;
- while (idx < scheduler.labels.length && scheduler.labels[idx].name != labelName) { idx = idx + 1; }
- if (idx < scheduler.queues.length && scheduler.labels[idx].name == labelName) {
- scheduler.queues[idx] = new Array();
+ while (idx < scheduler.labels.length && scheduler.labels[idx].name != label)
+ idx++;
+
+ return idx < scheduler.queues.length && scheduler.labels[idx].name == label ? idx : -1;
+ }
+
+ this.queueEmpty = function(label) {
+ var idx = scheduler.indexOf(label);
+ if (idx != -1)
+ return scheduler.queues[idx].length == 0;
+ else
+ throw("queue for label '" + label + "' is non-existent");
+ }
+
+ this.scheduleLast = function(label, fn) {
+ if (scheduler.queueEmpty(label)) {
+ fn();
+ } else {
+ scheduler.add(label, function() {
+ scheduler.scheduleLast(label, fn);
+ });
}
}
+
+ this.numberOfJobs = function(label) {
+ var index = scheduler.indexOf(label);
+ if (index == -1) throw("queue for label '" + label + "' non-existent");
+
+ return scheduler.queues[index].length;
+ }
};