taskbuffer/dist/taskbuffer.classes.helpers.js

83 lines
6.1 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();
taskArg.running = true;
done.promise.then(function () { taskArg.running = false; });
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.runningBuffered = true;
taskArg.bufferCounter--;
exports.runTask(taskArg)
.then(recursiveBufferRunner);
}
else {
taskArg.runningBuffered = false;
}
};
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza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