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;
|
||||||
}
|
}
|
||||||
|
41
dist/taskbuffer.classes.taskchain.js
vendored
41
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",
|
||||||
|
36
test/test.js
36
test/test.js
File diff suppressed because one or more lines are too long
35
test/test.ts
35
test/test.ts
@ -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(
|
||||||
|
{
|
||||||
|
name:"unnamed Task",
|
||||||
|
log:false
|
||||||
|
},
|
||||||
|
optionsArg,
|
||||||
|
{
|
||||||
taskFunction: () => { // this is the function that gets executed when TaskChain is triggered
|
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
|
console.log("running taskchain function");
|
||||||
let startDeferred = plugins.Q.defer(); // this is the starting Deferred object
|
let done = plugins.Q.defer(); // this is the starting Deferred object
|
||||||
let promisePointer = startDeferred.promise;
|
let taskCounter = 0;
|
||||||
for(let keyArg in this.taskArray){
|
let iterateTasks = () => {
|
||||||
promisePointer.then(function(){
|
if(typeof this.taskArray[taskCounter] != "undefined"){
|
||||||
promisePointer = this.taskArray[keyArg].trigger();
|
this.taskArray[taskCounter].trigger()
|
||||||
return promisePointer;
|
.then(()=>{
|
||||||
})
|
taskCounter++;
|
||||||
};
|
iterateTasks();
|
||||||
startDeferred.resolve();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
} 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