60 lines
3.7 KiB
JavaScript
60 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';
|
|
let options = optionsArg;
|
|
this.taskFunction = optionsArg.taskFunction;
|
|
this.preTask = options.preTask;
|
|
this.afterTask = options.afterTask;
|
|
this.idle = !this.running;
|
|
this.buffered = options.buffered;
|
|
this.bufferRunner.setBufferMax(options.bufferMax);
|
|
this.name = options.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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMudGFzay50cyJdLCJuYW1lcyI6W10sIm1hc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