2016-05-15 13:28:38 +00:00
|
|
|
import * as plugins from "./taskbuffer.plugins"
|
|
|
|
import * as helpers from "./taskbuffer.classes.helpers"
|
2016-08-01 11:17:15 +00:00
|
|
|
import { Task } from "./taskbuffer.classes.task"
|
2016-05-15 13:28:38 +00:00
|
|
|
|
|
|
|
export class Taskparallel extends Task {
|
2016-08-01 11:17:15 +00:00
|
|
|
taskArray: Task[];
|
|
|
|
constructor(optionsArg: {
|
|
|
|
taskArray: Task[]
|
2016-05-15 13:28:38 +00:00
|
|
|
}){
|
2016-08-01 11:17:15 +00:00
|
|
|
let options = plugins.lodash.merge(
|
2016-05-15 13:28:38 +00:00
|
|
|
optionsArg,
|
|
|
|
{
|
2016-08-01 11:17:15 +00:00
|
|
|
taskFunction: () => {
|
2016-05-15 13:28:38 +00:00
|
|
|
let done = plugins.Q.defer();
|
2016-08-01 11:17:15 +00:00
|
|
|
let promiseArray:PromiseLike<any>[] = []; // stores promises of all tasks, since they run in parallel
|
|
|
|
this.taskArray.forEach(function (taskArg) {
|
2016-05-15 13:28:38 +00:00
|
|
|
promiseArray.push(taskArg.trigger());
|
|
|
|
})
|
|
|
|
plugins.Q.all(promiseArray)
|
|
|
|
.then(done.resolve);
|
|
|
|
return done.promise;
|
|
|
|
}
|
|
|
|
}
|
2016-08-01 11:17:15 +00:00
|
|
|
);
|
2016-05-15 13:28:38 +00:00
|
|
|
super(options);
|
2016-08-01 11:17:15 +00:00
|
|
|
this.taskArray = optionsArg.taskArray;
|
2016-05-15 13:28:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|