taskbuffer/dist/taskbuffer.classes.task.js

59 lines
3.6 KiB
JavaScript

"use strict";
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";
var 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMudGFzay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsZ0RBQStDO0FBQy9DLHdEQUF1RDtBQU12RDtJQWNJLFlBQVksVUFPWDtRQWRELHdCQUF3QjtRQUN4QixZQUFPLEdBQVcsS0FBSyxDQUFDO1FBQ3hCLGlCQUFZLEdBQUcsSUFBSSxPQUFPLENBQUMsWUFBWSxDQUFDLElBQUksQ0FBQyxDQUFDO1FBQzlDLGlCQUFZLEdBQUcsSUFBSSxPQUFPLENBQUMsWUFBWSxDQUFDLElBQUksQ0FB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