improve options handling between classes
This commit is contained in:
@ -2,7 +2,6 @@
|
||||
import * as plugins from "./taskbuffer.plugins"
|
||||
import * as helpers from "./taskbuffer.classes.helpers"
|
||||
|
||||
|
||||
export class Task {
|
||||
name:string;
|
||||
task:any;
|
||||
@ -16,7 +15,14 @@ export class Task {
|
||||
preTask:Task;
|
||||
afterTask:Task;
|
||||
|
||||
constructor(optionsArg:{taskFunction:any,preTask?:Task,afterTask?:Task, buffered?:boolean, bufferMax?:number}){
|
||||
constructor(optionsArg:{
|
||||
taskFunction:any,
|
||||
preTask?:Task,
|
||||
afterTask?:Task,
|
||||
buffered?:boolean,
|
||||
bufferMax?:number,
|
||||
name?:string
|
||||
}){
|
||||
if (!optionsArg){optionsArg = {taskFunction:function(){}}}
|
||||
var options = optionsArg;
|
||||
this.task = optionsArg.taskFunction;
|
||||
@ -26,6 +32,7 @@ export class Task {
|
||||
this.idle = true;
|
||||
this.buffered = options.buffered;
|
||||
this.bufferMax = options.bufferMax;
|
||||
this.name = options.name;
|
||||
}
|
||||
|
||||
trigger(){
|
||||
|
@ -6,8 +6,11 @@ import helpers = require("./taskbuffer.classes.helpers");
|
||||
export class Taskchain extends Task {
|
||||
taskArray:Task[];
|
||||
private _oraObject;
|
||||
constructor(taskArrayArg:Task[]|Task){
|
||||
super({
|
||||
constructor(optionsArg:{
|
||||
taskArray:Task[]
|
||||
name?:string
|
||||
}){
|
||||
let options = plugins.lodash.assign(optionsArg,{
|
||||
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
|
||||
@ -21,6 +24,8 @@ export class Taskchain extends Task {
|
||||
startDeferred.resolve();
|
||||
}
|
||||
});
|
||||
super(options);
|
||||
this.taskArray = optionsArg.taskArray;
|
||||
this._oraObject = plugins.beautylog.ora("Taskchain idle","blue");
|
||||
}
|
||||
addTask(taskArg:Task){
|
||||
@ -32,10 +37,17 @@ export class Taskchain extends Task {
|
||||
shiftTask(){
|
||||
|
||||
};
|
||||
trigger(){
|
||||
this._oraObject.start(this.name + "running");
|
||||
}
|
||||
};
|
||||
|
||||
let myTask = new Taskchain(
|
||||
new Task({
|
||||
taskFunction:function(){}
|
||||
})
|
||||
{
|
||||
taskArray: [
|
||||
new Task({
|
||||
taskFunction:function(){}
|
||||
})
|
||||
]
|
||||
}
|
||||
);
|
@ -1,3 +1,4 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
export import beautylog = require("beautylog");
|
||||
export let Q = require("q");
|
||||
export let lodash= require("lodash");
|
||||
|
Reference in New Issue
Block a user