93 lines
6.7 KiB
JavaScript
93 lines
6.7 KiB
JavaScript
"use strict";
|
|
const plugins = require("./taskbuffer.plugins");
|
|
const taskbuffer_classes_task_1 = require("./taskbuffer.classes.task");
|
|
exports.emptyTaskFunction = function () {
|
|
let done = plugins.Q.defer();
|
|
done.resolve();
|
|
return done.promise;
|
|
};
|
|
exports.isTask = function (taskArg) {
|
|
if (taskArg instanceof taskbuffer_classes_task_1.Task
|
|
&& typeof taskArg.task === "function") {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
};
|
|
exports.isTaskTouched = (taskArg, touchedTasksArray) => {
|
|
let result = false;
|
|
for (let keyArg in touchedTasksArray) {
|
|
if (taskArg === touchedTasksArray[keyArg]) {
|
|
result = true;
|
|
}
|
|
}
|
|
return result;
|
|
};
|
|
exports.runTask = function (taskArg, optionsArg = { touchedTasksArray: [] }) {
|
|
let done = plugins.Q.defer();
|
|
exports.updateTaskStatus(taskArg, "running");
|
|
done.promise.then(function () { exports.updateTaskStatus(taskArg, "idle"); });
|
|
let localDeferred = plugins.Q.defer();
|
|
let touchedTasksArray;
|
|
if (optionsArg.touchedTasksArray) {
|
|
touchedTasksArray = optionsArg.touchedTasksArray;
|
|
}
|
|
else {
|
|
touchedTasksArray = [];
|
|
}
|
|
touchedTasksArray.push(taskArg);
|
|
localDeferred.promise
|
|
.then(() => {
|
|
if (taskArg.preTask && !exports.isTaskTouched(taskArg.preTask, touchedTasksArray)) {
|
|
return exports.runTask(taskArg.preTask, { touchedTasksArray: touchedTasksArray });
|
|
}
|
|
else {
|
|
let done2 = plugins.Q.defer();
|
|
done2.resolve();
|
|
return done2.promise;
|
|
}
|
|
})
|
|
.then(() => {
|
|
return taskArg.task();
|
|
})
|
|
.then(() => {
|
|
if (taskArg.afterTask && !exports.isTaskTouched(taskArg.afterTask, touchedTasksArray)) {
|
|
return exports.runTask(taskArg.afterTask, { touchedTasksArray: touchedTasksArray });
|
|
}
|
|
else {
|
|
let done2 = plugins.Q.defer();
|
|
done2.resolve();
|
|
return done2.promise;
|
|
}
|
|
})
|
|
.then(() => {
|
|
done.resolve();
|
|
});
|
|
localDeferred.resolve();
|
|
return done.promise;
|
|
};
|
|
exports.runBufferedTask = (taskArg) => {
|
|
let recursiveBufferRunner = () => {
|
|
if (taskArg.bufferCounter > 0) {
|
|
taskArg.bufferCounter--;
|
|
exports.runTask(taskArg)
|
|
.then(recursiveBufferRunner);
|
|
}
|
|
};
|
|
};
|
|
exports.updateTaskStatus = (taskArg, statusArg) => {
|
|
switch (statusArg) {
|
|
case "running":
|
|
taskArg.running = true;
|
|
taskArg.idle = false;
|
|
break;
|
|
case "idle":
|
|
taskArg.running = false;
|
|
taskArg.idle = true;
|
|
break;
|
|
default:
|
|
throw new Error("status not recognised");
|
|
}
|
|
};
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBTyxPQUFPLFdBQVcsc0JBQXNCLENBQUMsQ0FBQztBQUNqRCwwQ0FBbUIsMkJBQTJCLENBQUMsQ0FBQTtBQUVwQyx5QkFBaUIsR0FBRztJQUMzQixJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO0lBQzdCLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQztJQUNmLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0FBQ3hCLENBQUMsQ0FBQztBQUVTLGNBQU0sR0FBRyxVQUFTLE9BQU87SUFDaEMsRUFBRSxDQUFBLENBQ0UsT0FBTyxZQUFZLDhCQUFJO1dBQ3BCLE9BQU8sT0FBTyxDQUFDLElBQUksS0FBSyxV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