taskbuffer/ts/taskbuffer.classes.taskparallel.ts

25 lines
775 B
TypeScript
Raw Permalink Normal View History

2022-03-25 11:14:49 +00:00
import * as plugins from './taskbuffer.plugins.js';
import { Task } from './taskbuffer.classes.task.js';
export class Taskparallel extends Task {
2019-11-27 23:34:45 +00:00
public taskArray: Task[];
2018-08-04 15:53:22 +00:00
constructor(optionsArg: { taskArray: Task[] }) {
const options = {
...optionsArg,
...{
2017-06-17 14:56:33 +00:00
taskFunction: () => {
2019-11-27 23:34:45 +00:00
const done = plugins.smartpromise.defer();
const promiseArray: Promise<any>[] = []; // stores promises of all tasks, since they run in parallel
2020-07-12 00:48:51 +00:00
this.taskArray.forEach(function (taskArg) {
2018-08-04 15:53:22 +00:00
promiseArray.push(taskArg.trigger());
});
Promise.all(promiseArray).then(done.resolve);
return done.promise;
2020-07-12 00:48:51 +00:00
},
},
2018-08-04 15:53:22 +00:00
};
super(options);
this.taskArray = optionsArg.taskArray;
2017-06-17 14:56:33 +00:00
}
}