2018-08-04 15:53:22 +00:00
|
|
|
import * as plugins from './taskbuffer.plugins';
|
|
|
|
import * as helpers from './taskbuffer.classes.helpers';
|
|
|
|
import { Task } from './taskbuffer.classes.task';
|
2016-05-15 13:28:38 +00:00
|
|
|
|
|
|
|
export class Taskparallel extends Task {
|
2018-08-04 15:53:22 +00:00
|
|
|
taskArray: Task[];
|
|
|
|
constructor(optionsArg: { taskArray: Task[] }) {
|
|
|
|
const options = {
|
|
|
|
...optionsArg,
|
|
|
|
...{
|
2017-06-17 14:56:33 +00:00
|
|
|
taskFunction: () => {
|
2018-08-04 15:53:22 +00:00
|
|
|
let done = plugins.smartpromise.defer();
|
|
|
|
let promiseArray: Promise<any>[] = []; // stores promises of all tasks, since they run in parallel
|
|
|
|
this.taskArray.forEach(function(taskArg) {
|
|
|
|
promiseArray.push(taskArg.trigger());
|
|
|
|
});
|
|
|
|
Promise.all(promiseArray).then(done.resolve);
|
|
|
|
return done.promise;
|
2017-06-17 14:56:33 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-04 15:53:22 +00:00
|
|
|
};
|
|
|
|
super(options);
|
|
|
|
this.taskArray = optionsArg.taskArray;
|
2017-06-17 14:56:33 +00:00
|
|
|
}
|
2016-05-15 13:28:38 +00:00
|
|
|
}
|