2016-05-04 02:28:50 +00:00
|
|
|
"use strict";
|
2016-07-31 22:53:27 +00:00
|
|
|
const plugins = require("./taskbuffer.plugins");
|
|
|
|
const taskbuffer_classes_task_1 = require("./taskbuffer.classes.task");
|
2016-05-04 00:49:43 +00:00
|
|
|
exports.emptyTaskFunction = function () {
|
2016-07-31 22:53:27 +00:00
|
|
|
let done = plugins.Q.defer();
|
2016-05-04 00:49:43 +00:00
|
|
|
done.resolve();
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-05-04 02:28:50 +00:00
|
|
|
exports.isTask = function (taskArg) {
|
2016-05-15 13:28:38 +00:00
|
|
|
if (taskArg instanceof taskbuffer_classes_task_1.Task
|
2016-05-04 02:28:50 +00:00
|
|
|
&& typeof taskArg.task === "function") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2016-07-31 22:53:27 +00:00
|
|
|
exports.isTaskTouched = (taskArg, touchedTasksArray) => {
|
|
|
|
let result = false;
|
|
|
|
for (let keyArg in touchedTasksArray) {
|
2016-05-06 00:05:45 +00:00
|
|
|
if (taskArg === touchedTasksArray[keyArg]) {
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2016-05-05 16:36:31 +00:00
|
|
|
};
|
2016-07-31 22:53:27 +00:00
|
|
|
exports.runTask = function (taskArg, optionsArg = { touchedTasksArray: [] }) {
|
|
|
|
let done = plugins.Q.defer();
|
2016-08-01 11:17:15 +00:00
|
|
|
taskArg.running = true;
|
|
|
|
done.promise.then(function () { taskArg.running = false; });
|
2016-07-31 22:53:27 +00:00
|
|
|
let localDeferred = plugins.Q.defer();
|
|
|
|
let touchedTasksArray;
|
2016-05-05 16:36:31 +00:00
|
|
|
if (optionsArg.touchedTasksArray) {
|
|
|
|
touchedTasksArray = optionsArg.touchedTasksArray;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
touchedTasksArray = [];
|
2016-05-04 00:49:43 +00:00
|
|
|
}
|
2016-05-05 16:36:31 +00:00
|
|
|
touchedTasksArray.push(taskArg);
|
|
|
|
localDeferred.promise
|
2016-07-31 22:53:27 +00:00
|
|
|
.then(() => {
|
2016-05-05 16:36:31 +00:00
|
|
|
if (taskArg.preTask && !exports.isTaskTouched(taskArg.preTask, touchedTasksArray)) {
|
|
|
|
return exports.runTask(taskArg.preTask, { touchedTasksArray: touchedTasksArray });
|
|
|
|
}
|
|
|
|
else {
|
2016-07-31 22:53:27 +00:00
|
|
|
let done2 = plugins.Q.defer();
|
2016-05-05 16:36:31 +00:00
|
|
|
done2.resolve();
|
|
|
|
return done2.promise;
|
|
|
|
}
|
|
|
|
})
|
2016-07-31 22:53:27 +00:00
|
|
|
.then(() => {
|
2016-05-05 16:36:31 +00:00
|
|
|
return taskArg.task();
|
|
|
|
})
|
2016-07-31 22:53:27 +00:00
|
|
|
.then(() => {
|
2016-05-05 16:36:31 +00:00
|
|
|
if (taskArg.afterTask && !exports.isTaskTouched(taskArg.afterTask, touchedTasksArray)) {
|
|
|
|
return exports.runTask(taskArg.afterTask, { touchedTasksArray: touchedTasksArray });
|
|
|
|
}
|
|
|
|
else {
|
2016-07-31 22:53:27 +00:00
|
|
|
let done2 = plugins.Q.defer();
|
2016-05-05 16:36:31 +00:00
|
|
|
done2.resolve();
|
|
|
|
return done2.promise;
|
|
|
|
}
|
|
|
|
})
|
2016-07-31 22:53:27 +00:00
|
|
|
.then(() => {
|
2016-05-05 16:36:31 +00:00
|
|
|
done.resolve();
|
|
|
|
});
|
2016-05-06 00:05:45 +00:00
|
|
|
localDeferred.resolve();
|
2016-05-04 00:49:43 +00:00
|
|
|
return done.promise;
|
|
|
|
};
|
2016-07-31 22:53:27 +00:00
|
|
|
exports.runBufferedTask = (taskArg) => {
|
|
|
|
let recursiveBufferRunner = () => {
|
2016-05-06 00:05:45 +00:00
|
|
|
if (taskArg.bufferCounter > 0) {
|
2016-08-01 11:17:15 +00:00
|
|
|
taskArg.runningBuffered = true;
|
2016-05-06 00:05:45 +00:00
|
|
|
taskArg.bufferCounter--;
|
|
|
|
exports.runTask(taskArg)
|
|
|
|
.then(recursiveBufferRunner);
|
|
|
|
}
|
2016-08-01 11:17:15 +00:00
|
|
|
else {
|
|
|
|
taskArg.runningBuffered = false;
|
|
|
|
}
|
2016-05-06 00:05:45 +00:00
|
|
|
};
|
|
|
|
};
|
2016-08-01 11:17:15 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBTyxPQUFPLFdBQVcsc0JBQXNCLENBQUMsQ0FBQztBQUNqRCwwQ0FBaUMsMkJBQTJCLENBQUMsQ0FBQTtBQUVsRCx5QkFBaUIsR0FBaUI7SUFDekMsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixJQUFJLENBQUMsT0FBTyxFQUFFLENBQUM7SUFDZixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztBQUN4QixDQUFDLENBQUM7QUFFUyxjQUFNLEdBQUcsVUFBUyxPQUFPO0lBQ2hDLEVBQUUsQ0FBQSxDQUNFLE9BQU8sWUFBWSw4QkFBSTtXQUNwQixPQUFPLE9BQU8sQ0FBQyxJQUFJLEtBQUssVUFDL0IsQ0FBQyxDQUFBLENBQUM7UUFDRSxNQUFNLENBQUMsSUFBSSxDQUFDO0lBQ2hCLENBQUM7SUFBQyxJQUFJLENBQUMsQ0FBQztRQUNKLE1BQU0sQ0FBQyxLQUFLLENBQUM7SUFDakIsQ0FBQztBQUNMLENBQUMsQ0FBQztBQUdTLHFCQUFhLEdBQUc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