2016-05-04 01:45:52 +00:00
|
|
|
/// <reference path="./typings/main.d.ts" />
|
2016-05-05 16:06:04 +00:00
|
|
|
import * as plugins from "./taskbuffer.plugins";
|
2016-05-05 17:21:01 +00:00
|
|
|
import {Task} from "./taskbuffer.classes";
|
2016-05-05 16:06:04 +00:00
|
|
|
import helpers = require("./taskbuffer.classes.helpers");
|
2016-05-04 01:44:54 +00:00
|
|
|
|
2016-05-05 17:21:01 +00:00
|
|
|
export class Taskchain extends Task {
|
|
|
|
taskArray:Task[];
|
2016-05-14 02:28:22 +00:00
|
|
|
private _oraObject;
|
2016-05-14 21:24:11 +00:00
|
|
|
constructor(optionsArg:{
|
|
|
|
taskArray:Task[]
|
|
|
|
name?:string
|
|
|
|
}){
|
|
|
|
let options = plugins.lodash.assign(optionsArg,{
|
2016-05-05 16:06:04 +00:00
|
|
|
taskFunction: () => { // this is the function that gets executed when TaskChain is triggered
|
|
|
|
if(this.taskArray.length = 0) return; //make sure there is actually a Task available to execute
|
|
|
|
let startDeferred = plugins.Q.defer(); // this is the starting Deferred object
|
|
|
|
let promisePointer = startDeferred.promise;
|
|
|
|
for(let keyArg in this.taskArray){
|
|
|
|
promisePointer.then(function(){
|
|
|
|
promisePointer = this.taskArray[keyArg].trigger();
|
|
|
|
return promisePointer;
|
|
|
|
})
|
|
|
|
};
|
|
|
|
startDeferred.resolve();
|
|
|
|
}
|
2016-05-04 01:44:54 +00:00
|
|
|
});
|
2016-05-14 21:24:11 +00:00
|
|
|
super(options);
|
|
|
|
this.taskArray = optionsArg.taskArray;
|
2016-05-14 02:28:22 +00:00
|
|
|
this._oraObject = plugins.beautylog.ora("Taskchain idle","blue");
|
2016-05-04 01:44:54 +00:00
|
|
|
}
|
2016-05-05 17:21:01 +00:00
|
|
|
addTask(taskArg:Task){
|
2016-05-05 16:06:04 +00:00
|
|
|
this.taskArray.push(taskArg);
|
|
|
|
};
|
2016-05-05 17:21:01 +00:00
|
|
|
removeTask(taskArg:Task){
|
2016-05-05 16:06:04 +00:00
|
|
|
//TODO
|
|
|
|
};
|
|
|
|
shiftTask(){
|
|
|
|
|
|
|
|
};
|
2016-05-14 21:24:11 +00:00
|
|
|
trigger(){
|
|
|
|
this._oraObject.start(this.name + "running");
|
|
|
|
}
|
2016-05-05 16:06:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let myTask = new Taskchain(
|
2016-05-14 21:24:11 +00:00
|
|
|
{
|
|
|
|
taskArray: [
|
|
|
|
new Task({
|
|
|
|
taskFunction:function(){}
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}
|
2016-05-05 16:06:04 +00:00
|
|
|
);
|