64 lines
7.0 KiB
JavaScript
64 lines
7.0 KiB
JavaScript
"use strict";
|
|
/// <reference path="./typings/main.d.ts" />
|
|
var plugins = require("./taskbuffer.plugins");
|
|
var taskbuffer_classes_1 = require("./taskbuffer.classes");
|
|
exports.emptyTaskFunction = function () {
|
|
var done = plugins.Q.defer();
|
|
done.resolve();
|
|
return done.promise;
|
|
};
|
|
exports.isTask = function (taskArg) {
|
|
if (taskArg instanceof taskbuffer_classes_1.Task
|
|
&& typeof taskArg.task === "function") {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
};
|
|
exports.isTaskTouched = function (task, touchedTasksArray) {
|
|
return false;
|
|
};
|
|
exports.runTask = function (taskArg, optionsArg) {
|
|
var done = plugins.Q.defer();
|
|
var localDeferred = plugins.Q.defer();
|
|
var touchedTasksArray;
|
|
if (optionsArg.touchedTasksArray) {
|
|
touchedTasksArray = optionsArg.touchedTasksArray;
|
|
}
|
|
else {
|
|
touchedTasksArray = [];
|
|
}
|
|
touchedTasksArray.push(taskArg);
|
|
localDeferred.promise
|
|
.then(function () {
|
|
if (taskArg.preTask && !exports.isTaskTouched(taskArg.preTask, touchedTasksArray)) {
|
|
return exports.runTask(taskArg.preTask, { touchedTasksArray: touchedTasksArray });
|
|
}
|
|
else {
|
|
var done2 = plugins.Q.resolve();
|
|
done2.resolve();
|
|
return done2.promise;
|
|
}
|
|
})
|
|
.then(function () {
|
|
return taskArg.task();
|
|
})
|
|
.then(function () {
|
|
if (taskArg.afterTask && !exports.isTaskTouched(taskArg.afterTask, touchedTasksArray)) {
|
|
return exports.runTask(taskArg.afterTask, { touchedTasksArray: touchedTasksArray });
|
|
}
|
|
else {
|
|
var done2 = plugins.Q.resolve();
|
|
done2.resolve();
|
|
return done2.promise;
|
|
}
|
|
})
|
|
.then(function () {
|
|
done.resolve();
|
|
});
|
|
return done.promise;
|
|
};
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3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XJyYXk6dG91Y2hlZFRhc2tzQXJyYXl9KVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBsZXQgZG9uZTIgPSBwbHVnaW5zLlEucmVzb2x2ZSgpO1xuICAgICAgICAgICAgICAgIGRvbmUyLnJlc29sdmUoKTtcbiAgICAgICAgICAgICAgICByZXR1cm4gZG9uZTIucHJvbWlzZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSlcbiAgICAgICAgLnRoZW4oKCkgPT4ge1xuICAgICAgICAgICAgcmV0dXJuIHRhc2tBcmcudGFzaygpO1xuICAgICAgICB9KVxuICAgICAgICAudGhlbigoKSA9PiB7XG4gICAgICAgICAgICBpZih0YXNrQXJnLmFmdGVyVGFzayAmJiAhaXNUYXNrVG91Y2hlZCh0YXNrQXJnLmFmdGVyVGFzayx0b3VjaGVkVGFza3NBcnJheSkpe1xuICAgICAgICAgICAgICAgIHJldHVybiBydW5UYXNrKHRhc2tBcmcuYWZ0ZXJUYXNrLHt0b3VjaGVkVGFza3NBcnJheTp0b3VjaGVkVGFza3NBcnJheX0pXG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGxldCBkb25lMiA9IHBsdWdpbnMuUS5yZXNvbHZlKCk7XG4gICAgICAgICAgICAgICAgZG9uZTIucmVzb2x2ZSgpO1xuICAgICAgICAgICAgICAgIHJldHVybiBkb25lMi5wcm9taXNlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KVxuICAgICAgICAudGhlbigoKSA9PiB7XG4gICAgICAgICAgICBkb25lLnJlc29sdmUoKTtcbiAgICAgICAgfSlcbiAgICAgICAgXG4gICAgcmV0dXJuIGRvbmUucHJvbWlzZTtcbn07Il19
|