taskbuffer/ts/taskbuffer.classes.taskparallel.ts

30 lines
975 B
TypeScript
Raw Normal View History

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"
export class Taskparallel extends Task {
2016-08-01 11:17:15 +00:00
taskArray: Task[];
constructor(optionsArg: {
taskArray: Task[]
}){
2016-08-01 11:17:15 +00:00
let options = plugins.lodash.merge(
optionsArg,
{
2016-08-01 11:17:15 +00:00
taskFunction: () => {
2017-01-19 16:26:35 +00:00
let done = plugins.q.defer();
let promiseArray: Promise<any>[] = []; // stores promises of all tasks, since they run in parallel
2016-08-01 11:17:15 +00:00
this.taskArray.forEach(function (taskArg) {
promiseArray.push(taskArg.trigger());
})
2017-01-19 16:26:35 +00:00
Promise.all(promiseArray)
.then(done.resolve);
return done.promise;
}
}
2016-08-01 11:17:15 +00:00
);
super(options);
2016-08-01 11:17:15 +00:00
this.taskArray = optionsArg.taskArray;
}
}