now logging allright

This commit is contained in:
Philipp Kunz 2016-05-15 15:52:59 +02:00
parent 8944ae2462
commit 19beb95e20
4 changed files with 17 additions and 15 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -57,8 +57,7 @@ describe("taskbuffer",function(){
name:"task1", name:"task1",
taskFunction:function(){ taskFunction:function(){
let done = plugins.q.defer(); let done = plugins.q.defer();
console.log("Task1 run"); setTimeout(done.resolve,2000);
done.resolve();
return done.promise; return done.promise;
} }
}), }),
@ -66,13 +65,13 @@ describe("taskbuffer",function(){
name:"task2", name:"task2",
taskFunction: function(){ taskFunction: function(){
let done = plugins.q.defer(); let done = plugins.q.defer();
console.log("Task2 run"); setTimeout(done.resolve,2000);
done.resolve();
return done.promise; return done.promise;
} }
}), }),
]; ];
it("should run tasks in sequence",function(done){ it("should run tasks in sequence",function(done){
this.timeout(5000);
testTaskchain = new taskbuffer.Taskchain({ testTaskchain = new taskbuffer.Taskchain({
name:"Taskchain1", name:"Taskchain1",
taskArray:testTaskArray taskArray:testTaskArray

View File

@ -5,7 +5,7 @@ import helpers = require("./taskbuffer.classes.helpers");
export class Taskchain extends Task { export class Taskchain extends Task {
taskArray:Task[]; taskArray:Task[];
private _oraObject; private _oraObject:plugins.beautylog.Ora;
constructor(optionsArg:{ constructor(optionsArg:{
name?:string, name?:string,
log?:boolean, log?:boolean,
@ -13,23 +13,25 @@ export class Taskchain extends Task {
}){ }){
let options = plugins.lodash.assign( let options = plugins.lodash.assign(
{ {
name:"unnamed Task", name:"unnamed Taskchain",
log:false log:false
}, },
optionsArg, 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
console.log("running taskchain function");
let done = plugins.Q.defer(); // this is the starting Deferred object let done = plugins.Q.defer(); // this is the starting Deferred object
let taskCounter = 0; let taskCounter = 0;
let iterateTasks = () => { let iterateTasks = () => {
if(typeof this.taskArray[taskCounter] != "undefined"){ if(typeof this.taskArray[taskCounter] != "undefined"){
this._oraObject.text(this.name + " running: Task" + this.taskArray[taskCounter].name);
this.taskArray[taskCounter].trigger() this.taskArray[taskCounter].trigger()
.then(()=>{ .then(()=>{
this._oraObject.log(this.taskArray[taskCounter].name,"ok");
taskCounter++; taskCounter++;
iterateTasks(); iterateTasks();
}); });
} else { } else {
this._oraObject.endOk("Taskchain \"" + this.name + "\" completed successfully");
done.resolve(); done.resolve();
} }
}; };