implemented execDelay
This commit is contained in:
parent
01d469960e
commit
3f275ebc08
2
dist/taskbuffer.classes.helpers.d.ts
vendored
2
dist/taskbuffer.classes.helpers.d.ts
vendored
@ -21,10 +21,8 @@ export declare class CycleCounter {
|
||||
export declare class BufferRunner {
|
||||
task: Task;
|
||||
bufferCounter: number;
|
||||
bufferMax: number;
|
||||
running: boolean;
|
||||
constructor(taskArg: Task);
|
||||
setBufferMax(bufferMaxArg: number): void;
|
||||
trigger(x: any): Promise<any>;
|
||||
private _run(x);
|
||||
}
|
||||
|
28
dist/taskbuffer.classes.helpers.js
vendored
28
dist/taskbuffer.classes.helpers.js
vendored
File diff suppressed because one or more lines are too long
25
dist/taskbuffer.classes.task.d.ts
vendored
25
dist/taskbuffer.classes.task.d.ts
vendored
@ -6,6 +6,8 @@ export declare class Task {
|
||||
name: string;
|
||||
taskFunction: ITaskFunction;
|
||||
buffered: boolean;
|
||||
bufferMax: number;
|
||||
execDelay: number;
|
||||
preTask: Task;
|
||||
afterTask: Task;
|
||||
running: boolean;
|
||||
@ -14,11 +16,34 @@ export declare class Task {
|
||||
idle: boolean;
|
||||
private _state;
|
||||
constructor(optionsArg: {
|
||||
/**
|
||||
* the task function to run, must return promise
|
||||
*/
|
||||
taskFunction: ITaskFunction;
|
||||
/**
|
||||
* any other task to run before
|
||||
*/
|
||||
preTask?: Task;
|
||||
/**
|
||||
* any other task to run after
|
||||
*/
|
||||
afterTask?: Task;
|
||||
/**
|
||||
* wether this task should run buffered
|
||||
*/
|
||||
buffered?: boolean;
|
||||
/**
|
||||
* the maximum buffer
|
||||
*/
|
||||
bufferMax?: number;
|
||||
/**
|
||||
* the execution delay, before the task is executed
|
||||
* only makes sense when running in buffered mode
|
||||
*/
|
||||
execDelay?: number;
|
||||
/**
|
||||
* the name of the task
|
||||
*/
|
||||
name?: string;
|
||||
});
|
||||
/**
|
||||
|
14
dist/taskbuffer.classes.task.js
vendored
14
dist/taskbuffer.classes.task.js
vendored
@ -10,14 +10,14 @@ class Task {
|
||||
this.cycleCounter = new helpers.CycleCounter(this);
|
||||
this.idle = true;
|
||||
this._state = 'ready';
|
||||
let options = optionsArg;
|
||||
this.taskFunction = optionsArg.taskFunction;
|
||||
this.preTask = options.preTask;
|
||||
this.afterTask = options.afterTask;
|
||||
this.preTask = optionsArg.preTask;
|
||||
this.afterTask = optionsArg.afterTask;
|
||||
this.idle = !this.running;
|
||||
this.buffered = options.buffered;
|
||||
this.bufferRunner.setBufferMax(options.bufferMax);
|
||||
this.name = options.name;
|
||||
this.buffered = optionsArg.buffered;
|
||||
this.bufferMax = optionsArg.bufferMax;
|
||||
this.execDelay = optionsArg.execDelay;
|
||||
this.name = optionsArg.name;
|
||||
}
|
||||
/**
|
||||
* trigger the task. Will trigger buffered if this.buffered is true
|
||||
@ -55,4 +55,4 @@ class Task {
|
||||
}
|
||||
}
|
||||
exports.Task = Task;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMudGFzay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLGdEQUErQztBQUMvQyx3REFBdUQ7QUFNdkQ7SUFjRSxZQUFhLFVBT1o7UUFkRCx3QkFBd0I7UUFDeEIsWUFBTyxHQUFZLEtBQUssQ0FBQTtRQUN4QixpQkFBWSxHQUFHLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQUM3QyxpQkFBWSxHQUFHLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQUM3QyxTQUFJLEdBQVksSUFBSSxDQUFBO1FBQ1osV0FBTSxHQUFXLE9BQU8sQ0FBQTtRQVU5QixJQUFJLE9BQU8sR0FBRyxVQUFVLENBQUE7UUFDeEIsSUFBSS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MsQ0FBQyxDQUFDLENBQUE7SUFDckMsQ0FBQztJQUVELElBQUksS0FBSztRQUNQLE1BQU0sQ0FBQyxJQUFJLENBQUMsTUFBTSxDQUFBO0lBQ3BCLENBQUM7SUFFRCxJQUFJLEtBQUssQ0FBQyxRQUFnQjtRQUN4QixFQUFFLENBQUMsQ0FBQyxRQUFRLEtBQUssUUFBUSxDQUFDLENBQUMsQ0FBQztZQUMxQixJQUFJLENBQUMsTUFBTSxHQUFHLFFBQVEsQ0FBQTtRQUN4QixDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDTixPQUFPLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQyxhQUFhLEdBQUcsUUFBUSxHQUFHLG1CQUFtQixDQUFDLENBQUE7UUFDekUsQ0FBQztJQUNILENBQUM7Q0FDRjtBQWxHRCxvQkFrR0MifQ==
|
@ -28,12 +28,18 @@ export let isTaskTouched = (taskArg: Task, touchedTasksArray: Task[]): boolean =
|
||||
return result
|
||||
}
|
||||
|
||||
export let runTask = function (taskArg: Task, optionsArg: { x?, touchedTasksArray?: Task[] }) {
|
||||
export let runTask = async (taskArg: Task, optionsArg: { x?, touchedTasksArray?: Task[] }) => {
|
||||
let done = plugins.q.defer()
|
||||
|
||||
// pay respect to execDelay
|
||||
if (taskArg.execDelay) {
|
||||
await plugins.smartdelay.delayFor(taskArg.execDelay)
|
||||
}
|
||||
|
||||
// set running params
|
||||
taskArg.running = true
|
||||
done.promise.then(function () { taskArg.running = false })
|
||||
|
||||
done.promise.then(async () => { taskArg.running = false })
|
||||
|
||||
// handle options
|
||||
let options = plugins.lodash.merge(
|
||||
@ -75,7 +81,7 @@ export let runTask = function (taskArg: Task, optionsArg: { x?, touchedTasksArra
|
||||
console.log(err)
|
||||
})
|
||||
localDeferred.resolve()
|
||||
return done.promise
|
||||
return await done.promise
|
||||
}
|
||||
|
||||
export interface cycleObject {
|
||||
@ -116,18 +122,13 @@ export class BufferRunner {
|
||||
task: Task
|
||||
// initialze by default
|
||||
bufferCounter: number = 0
|
||||
bufferMax: number = 1
|
||||
running: boolean = false
|
||||
constructor(taskArg: Task) {
|
||||
this.task = taskArg
|
||||
}
|
||||
|
||||
setBufferMax (bufferMaxArg: number) {
|
||||
this.bufferMax = bufferMaxArg
|
||||
}
|
||||
|
||||
trigger (x): Promise<any> {
|
||||
if (!(this.bufferCounter >= this.bufferMax)) {
|
||||
if (!(this.bufferCounter >= this.task.bufferMax)) {
|
||||
this.bufferCounter++
|
||||
}
|
||||
let returnPromise: Promise<any> = this.task.cycleCounter.getPromiseForCycle(this.bufferCounter + 1)
|
||||
|
@ -6,9 +6,15 @@ export interface ITaskFunction {
|
||||
}
|
||||
|
||||
export class Task {
|
||||
// man datory properties
|
||||
name: string
|
||||
taskFunction: ITaskFunction
|
||||
buffered: boolean
|
||||
|
||||
bufferMax: number
|
||||
execDelay: number
|
||||
|
||||
// tasks to run before and after
|
||||
preTask: Task
|
||||
afterTask: Task
|
||||
|
||||
@ -16,25 +22,49 @@ export class Task {
|
||||
running: boolean = false
|
||||
bufferRunner = new helpers.BufferRunner(this)
|
||||
cycleCounter = new helpers.CycleCounter(this)
|
||||
|
||||
idle: boolean = true
|
||||
private _state: string = 'ready'
|
||||
|
||||
constructor(optionsArg: {
|
||||
taskFunction: ITaskFunction,
|
||||
preTask?: Task,
|
||||
afterTask?: Task,
|
||||
buffered?: boolean,
|
||||
bufferMax?: number,
|
||||
/**
|
||||
* the task function to run, must return promise
|
||||
*/
|
||||
taskFunction: ITaskFunction
|
||||
/**
|
||||
* any other task to run before
|
||||
*/
|
||||
preTask?: Task
|
||||
/**
|
||||
* any other task to run after
|
||||
*/
|
||||
afterTask?: Task
|
||||
/**
|
||||
* wether this task should run buffered
|
||||
*/
|
||||
buffered?: boolean
|
||||
/**
|
||||
* the maximum buffer
|
||||
*/
|
||||
bufferMax?: number
|
||||
/**
|
||||
* the execution delay, before the task is executed
|
||||
* only makes sense when running in buffered mode
|
||||
*/
|
||||
execDelay?: number
|
||||
/**
|
||||
* the name of the task
|
||||
*/
|
||||
name?: string
|
||||
}) {
|
||||
let options = optionsArg
|
||||
this.taskFunction = optionsArg.taskFunction
|
||||
this.preTask = options.preTask
|
||||
this.afterTask = options.afterTask
|
||||
this.preTask = optionsArg.preTask
|
||||
this.afterTask = optionsArg.afterTask
|
||||
this.idle = !this.running
|
||||
this.buffered = options.buffered
|
||||
this.bufferRunner.setBufferMax(options.bufferMax)
|
||||
this.name = options.name
|
||||
this.buffered = optionsArg.buffered
|
||||
this.bufferMax = optionsArg.bufferMax
|
||||
this.execDelay = optionsArg.execDelay
|
||||
this.name = optionsArg.name
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,6 +95,7 @@ export class Task {
|
||||
get state(): string {
|
||||
return this._state
|
||||
}
|
||||
|
||||
set state(stateArg: string) {
|
||||
if (stateArg === 'locked') {
|
||||
this._state = 'locked'
|
||||
|
Loading…
Reference in New Issue
Block a user