taskbuffer/dist/taskbuffer.classes.taskchain.js

53 lines
4.1 KiB
JavaScript
Raw Normal View History

2016-05-04 02:28:50 +00:00
"use strict";
2017-06-17 14:56:33 +00:00
// TaskChain chains tasks
// and extends Task
2017-06-09 21:26:23 +00:00
Object.defineProperty(exports, "__esModule", { value: true });
2016-07-31 22:53:27 +00:00
const plugins = require("./taskbuffer.plugins");
const taskbuffer_classes_task_1 = require("./taskbuffer.classes.task");
class Taskchain extends taskbuffer_classes_task_1.Task {
constructor(optionsArg) {
2016-08-01 11:17:15 +00:00
let options = plugins.lodash.merge({
2017-02-15 21:52:29 +00:00
name: 'unnamed Taskchain',
2016-05-15 01:16:50 +00:00
log: false
}, optionsArg, {
taskFunction: (x) => {
2017-02-15 21:52:29 +00:00
let done = plugins.q.defer(); // this is the starting Deferred object
let taskCounter = 0; // counter for iterating async over the taskArray
let iterateTasks = (x) => {
2017-02-15 21:52:29 +00:00
if (typeof this.taskArray[taskCounter] !== 'undefined') {
this._oraObject.text(this.name + ' running: Task' + this.taskArray[taskCounter].name);
this.taskArray[taskCounter].trigger(x)
.then((x) => {
2016-08-01 11:17:15 +00:00
plugins.beautylog.ok(this.taskArray[taskCounter].name);
2016-05-15 01:16:50 +00:00
taskCounter++;
iterateTasks(x);
2016-05-15 01:16:50 +00:00
});
}
else {
2017-02-15 21:52:29 +00:00
this._oraObject.endOk('Taskchain "' + this.name + '" completed successfully');
done.resolve(x);
2016-05-15 01:16:50 +00:00
}
};
iterateTasks(x);
2016-05-15 01:16:50 +00:00
return done.promise;
}
2016-05-04 02:28:50 +00:00
});
2016-07-31 22:53:27 +00:00
super(options);
this.taskArray = optionsArg.taskArray;
2017-02-15 21:52:29 +00:00
this._oraObject = plugins.beautylog.ora;
2016-08-01 11:17:15 +00:00
if (optionsArg.log === true) {
this._oraObject.start();
}
2016-05-04 02:28:50 +00:00
}
2016-07-31 22:53:27 +00:00
addTask(taskArg) {
this.taskArray.push(taskArg);
2016-07-31 22:53:27 +00:00
}
removeTask(taskArg) {
2017-06-09 21:33:41 +00:00
// TODO:
2016-07-31 22:53:27 +00:00
}
shiftTask() {
2017-06-09 21:33:41 +00:00
// TODO:
2016-07-31 22:53:27 +00:00
}
}
2016-05-04 02:28:50 +00:00
exports.Taskchain = Taskchain;
2017-06-17 14:56:33 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2tjaGFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3Rhc2tidWZmZXIuY2xhc3Nlcy50YXNrY2hhaW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHlCQUF5QjtBQUN6QixtQkFBbUI7O0FBRW5CLGdEQUErQztBQUMvQyx1RUFBZ0Q7QUFHaEQsZUFBdUIsU0FBUSw4QkFBSTtJQUdqQyxZQUFZLFVBTVg7UUFDQyxJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FDaEM7WUFDRSxJQUFJLEVBQUUsbUJBQW1CO1lBQ3pCLEdBQUcsRUFBRSxLQUFLO1NBQ1gsRUFDRCxVQUFVLEVBQ1Y7WUFDRSxZQUFZLEVBQUUsQ0FBQyxDQUFNO2dCQUNuQixJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFBLENBQUMsdUNBQXVDO2dCQUNwRSxJQUFJLFdBQVcsR0FBRyxDQUFDLENBQUEsQ0FBQyxpREFBaUQ7Z0JBQ3JFLElBQUksWUFBWSxHQUFHLENBQUMsQ0FBQztvQkFDbkIsRUFBRSxDQUFDLENBQUMsT0FBTyxJQUFJLENBQUMsU0FBUyxDQUFFLFdBQVcsQ0FBRSxLQUFLLFdBQVcsQ0FBQyxDQUFDLENBQUM7d0JBQ3pELElBQUksQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLElB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