now has working taskchain
This commit is contained in:
parent
454a999a42
commit
1714f552ac
5
dist/taskbuffer.classes.taskchain.d.ts
vendored
5
dist/taskbuffer.classes.taskchain.d.ts
vendored
@ -3,11 +3,12 @@ export declare class Taskchain extends Task {
|
|||||||
taskArray: Task[];
|
taskArray: Task[];
|
||||||
private _oraObject;
|
private _oraObject;
|
||||||
constructor(optionsArg: {
|
constructor(optionsArg: {
|
||||||
taskArray: Task[];
|
|
||||||
name?: string;
|
name?: string;
|
||||||
|
log?: boolean;
|
||||||
|
taskArray: Task[];
|
||||||
});
|
});
|
||||||
addTask(taskArg: Task): void;
|
addTask(taskArg: Task): void;
|
||||||
removeTask(taskArg: Task): void;
|
removeTask(taskArg: Task): void;
|
||||||
shiftTask(): void;
|
shiftTask(): void;
|
||||||
trigger(): void;
|
trigger(): any;
|
||||||
}
|
}
|
||||||
|
43
dist/taskbuffer.classes.taskchain.js
vendored
43
dist/taskbuffer.classes.taskchain.js
vendored
File diff suppressed because one or more lines are too long
@ -23,7 +23,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/taskbuffer#readme",
|
"homepage": "https://github.com/pushrocks/taskbuffer#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "^4.2.0",
|
"beautylog": "^5.0.0",
|
||||||
"lodash": "^4.12.0",
|
"lodash": "^4.12.0",
|
||||||
"projectinfo": "1.0.1",
|
"projectinfo": "1.0.1",
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
|
38
test/test.js
38
test/test.js
File diff suppressed because one or more lines are too long
37
test/test.ts
37
test/test.ts
@ -5,7 +5,7 @@ let plugins = {
|
|||||||
q: require("q")
|
q: require("q")
|
||||||
}
|
}
|
||||||
|
|
||||||
//setup some testData to work with
|
// setup some testData to work with
|
||||||
let testTask:taskbuffer.Task;
|
let testTask:taskbuffer.Task;
|
||||||
let testTaskFunction = function(){
|
let testTaskFunction = function(){
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
@ -45,5 +45,40 @@ describe("taskbuffer",function(){
|
|||||||
testTask.trigger()
|
testTask.trigger()
|
||||||
.then(done);
|
.then(done);
|
||||||
});
|
});
|
||||||
|
it("should run a task without pre and afterTask",function(done){
|
||||||
|
let localTestTask = new taskbuffer.Task({taskFunction:testTaskFunction});
|
||||||
|
localTestTask.trigger().then(done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe("Taskchain",function(){
|
||||||
|
let testTaskchain;
|
||||||
|
let testTaskArray = [
|
||||||
|
new taskbuffer.Task({
|
||||||
|
name:"task1",
|
||||||
|
taskFunction:function(){
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
console.log("Task1 run");
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
new taskbuffer.Task({
|
||||||
|
name:"task2",
|
||||||
|
taskFunction: function(){
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
console.log("Task2 run");
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
it("should run tasks in sequence",function(done){
|
||||||
|
testTaskchain = new taskbuffer.Taskchain({
|
||||||
|
name:"Taskchain1",
|
||||||
|
taskArray:testTaskArray
|
||||||
|
});
|
||||||
|
testTaskchain.trigger().then(done);
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -7,26 +7,40 @@ export class Taskchain extends Task {
|
|||||||
taskArray:Task[];
|
taskArray:Task[];
|
||||||
private _oraObject;
|
private _oraObject;
|
||||||
constructor(optionsArg:{
|
constructor(optionsArg:{
|
||||||
|
name?:string,
|
||||||
|
log?:boolean,
|
||||||
taskArray:Task[]
|
taskArray:Task[]
|
||||||
name?:string
|
|
||||||
}){
|
}){
|
||||||
let options = plugins.lodash.assign(optionsArg,{
|
let options = plugins.lodash.assign(
|
||||||
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
|
name:"unnamed Task",
|
||||||
let startDeferred = plugins.Q.defer(); // this is the starting Deferred object
|
log:false
|
||||||
let promisePointer = startDeferred.promise;
|
},
|
||||||
for(let keyArg in this.taskArray){
|
optionsArg,
|
||||||
promisePointer.then(function(){
|
{
|
||||||
promisePointer = this.taskArray[keyArg].trigger();
|
taskFunction: () => { // this is the function that gets executed when TaskChain is triggered
|
||||||
return promisePointer;
|
console.log("running taskchain function");
|
||||||
})
|
let done = plugins.Q.defer(); // this is the starting Deferred object
|
||||||
};
|
let taskCounter = 0;
|
||||||
startDeferred.resolve();
|
let iterateTasks = () => {
|
||||||
|
if(typeof this.taskArray[taskCounter] != "undefined"){
|
||||||
|
this.taskArray[taskCounter].trigger()
|
||||||
|
.then(()=>{
|
||||||
|
taskCounter++;
|
||||||
|
iterateTasks();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
done.resolve();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
iterateTasks();
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
super(options);
|
super(options);
|
||||||
this.taskArray = optionsArg.taskArray;
|
this.taskArray = optionsArg.taskArray;
|
||||||
this._oraObject = plugins.beautylog.ora("Taskchain idle","blue");
|
this._oraObject = new plugins.beautylog.Ora("Taskchain idle","blue");
|
||||||
}
|
}
|
||||||
addTask(taskArg:Task){
|
addTask(taskArg:Task){
|
||||||
this.taskArray.push(taskArg);
|
this.taskArray.push(taskArg);
|
||||||
@ -38,7 +52,8 @@ export class Taskchain extends Task {
|
|||||||
|
|
||||||
};
|
};
|
||||||
trigger(){
|
trigger(){
|
||||||
this._oraObject.start(this.name + "running");
|
this._oraObject.start(this.name + " running...");
|
||||||
|
return helpers.runTask(this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user