fix(core): update
This commit is contained in:
@ -3,14 +3,14 @@ import * as helpers from './taskbuffer.classes.helpers';
|
||||
import { Task } from './taskbuffer.classes.task';
|
||||
|
||||
export class Taskparallel extends Task {
|
||||
taskArray: Task[];
|
||||
public taskArray: Task[];
|
||||
constructor(optionsArg: { taskArray: Task[] }) {
|
||||
const options = {
|
||||
...optionsArg,
|
||||
...{
|
||||
taskFunction: () => {
|
||||
let done = plugins.smartpromise.defer();
|
||||
let promiseArray: Promise<any>[] = []; // stores promises of all tasks, since they run in parallel
|
||||
const done = plugins.smartpromise.defer();
|
||||
const promiseArray: Promise<any>[] = []; // stores promises of all tasks, since they run in parallel
|
||||
this.taskArray.forEach(function(taskArg) {
|
||||
promiseArray.push(taskArg.trigger());
|
||||
});
|
||||
|
48
ts/taskbuffer.classes.taskrunner.ts
Normal file
48
ts/taskbuffer.classes.taskrunner.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import * as plugins from './taskbuffer.plugins';
|
||||
|
||||
import { Task } from './taskbuffer.classes.task';
|
||||
|
||||
export class TaskRunner {
|
||||
public maxParrallelJobs: number = 1;
|
||||
public status: 'stopped' | 'running' = 'stopped';
|
||||
public runningTasks: plugins.lik.Objectmap<Task> = new plugins.lik.Objectmap<Task>();
|
||||
public qeuedTasks: Task[] = [];
|
||||
|
||||
/**
|
||||
* adds a task to the qeue
|
||||
*/
|
||||
public addTask(taskArg: Task) {
|
||||
this.qeuedTasks.push(taskArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* set amount of parallel tasks
|
||||
* be careful, you might loose dependability of tasks
|
||||
*/
|
||||
public setMaxParallelJobs(maxParrallelJobsArg: number) {
|
||||
this.maxParrallelJobs = maxParrallelJobsArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* starts the task queue
|
||||
*/
|
||||
public start() {
|
||||
this.status = 'running';
|
||||
}
|
||||
|
||||
public async checkExecution() {
|
||||
if (this.runningTasks.getArray().length < this.maxParrallelJobs) {
|
||||
const nextJob = this.qeuedTasks.shift();
|
||||
this.runningTasks.add(nextJob);
|
||||
await nextJob.trigger();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* stops the task queue
|
||||
*/
|
||||
public stop() {
|
||||
this.status = 'stopped';
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user