taskbuffer/dist/taskbuffer.classes.task.js
2017-07-10 12:42:06 +02:00

58 lines
3.7 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./taskbuffer.plugins");
const helpers = require("./taskbuffer.classes.helpers");
class Task {
constructor(optionsArg) {
// initialize by default
this.running = false;
this.bufferRunner = new helpers.BufferRunner(this);
this.cycleCounter = new helpers.CycleCounter(this);
this.idle = true;
this._state = 'ready';
this.taskFunction = optionsArg.taskFunction;
this.preTask = optionsArg.preTask;
this.afterTask = optionsArg.afterTask;
this.idle = !this.running;
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
*/
trigger(x) {
if (this.buffered) {
return this.triggerBuffered(x);
}
else {
return this.triggerUnBuffered(x);
}
}
/**
* trigger task unbuffered.
*/
triggerUnBuffered(x) {
return helpers.runTask(this, { x: x });
}
/**
* trigger task buffered.
*/
triggerBuffered(x) {
return this.bufferRunner.trigger(x);
}
get state() {
return this._state;
}
set state(stateArg) {
if (stateArg === 'locked') {
this._state = 'locked';
}
else {
plugins.beautylog.error('state type ' + stateArg + ' could not be set');
}
}
}
exports.Task = Task;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMudGFzay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLGdEQUErQztBQUMvQyx3REFBdUQ7QUFNdkQ7SUFxQkUsWUFBWSxVQThCWDtRQXRDRCx3QkFBd0I7UUFDeEIsWUFBTyxHQUFZLEtBQUssQ0FBQTtRQUN4QixpQkFBWSxHQUFHLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsQ0F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