-
Notifications
You must be signed in to change notification settings - Fork 2
/
katex-helper.js
43 lines (37 loc) · 1.05 KB
/
katex-helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
let {exec} = require('child_process');
class TaskQueue {
constructor() {
this.queue = []; // The actual queue of task.
this.busy = false; // Indicate that if there's task running.
}
beginTasks() {
this.busy = true;
let front = this.queue.shift();
exec(front.command, (err, stdout, stderr) => {
setTimeout(() => {
// We can assume that current shell job is done.
// Run the callback and immediate start next task.
front.callback(err, stdout, stderr);
if (this.queue.length !== 0) {
this.beginTasks();
}
else {
// Well done.
this.busy = false;
}
}, 50);
});
}
push(task) {
this.queue.push(task);
if (!this.busy)
this.beginTasks();
}
}
let taskQueue = new TaskQueue();
module.exports = {
getTaskQueue: function() {
return taskQueue;
}
};