2019-09-23 16:06:43 +00:00
|
|
|
import * as plugins from './taskbuffer.plugins';
|
|
|
|
import { Task } from './taskbuffer.classes.task';
|
|
|
|
|
|
|
|
export interface ICycleObject {
|
|
|
|
cycleCounter: number;
|
|
|
|
deferred: plugins.smartpromise.Deferred<any>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class CycleCounter {
|
|
|
|
public task: Task;
|
|
|
|
public cycleObjectArray: ICycleObject[] = [];
|
|
|
|
constructor(taskArg: Task) {
|
|
|
|
this.task = taskArg;
|
|
|
|
}
|
|
|
|
public getPromiseForCycle(cycleCountArg: number) {
|
|
|
|
const done = plugins.smartpromise.defer();
|
|
|
|
const cycleObject: ICycleObject = {
|
|
|
|
cycleCounter: cycleCountArg,
|
2020-07-12 00:48:51 +00:00
|
|
|
deferred: done,
|
2019-09-23 16:06:43 +00:00
|
|
|
};
|
|
|
|
this.cycleObjectArray.push(cycleObject);
|
|
|
|
return done.promise;
|
|
|
|
}
|
|
|
|
public informOfCycle(x) {
|
|
|
|
const newCycleObjectArray: ICycleObject[] = [];
|
2020-07-12 00:48:51 +00:00
|
|
|
this.cycleObjectArray.forEach((cycleObjectArg) => {
|
2019-09-23 16:06:43 +00:00
|
|
|
cycleObjectArg.cycleCounter--;
|
|
|
|
if (cycleObjectArg.cycleCounter <= 0) {
|
|
|
|
cycleObjectArg.deferred.resolve(x);
|
|
|
|
} else {
|
|
|
|
newCycleObjectArray.push(cycleObjectArg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.cycleObjectArray = newCycleObjectArray;
|
|
|
|
}
|
|
|
|
}
|