taskbuffer/dist/taskbuffer.classes.task.js

59 lines
3.7 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.blue + " could not be set");
}
}
}
exports.Task = Task;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMudGFzay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0sc0JBQ3pCLENBQUMsQ0FEOEM7QUFDL0MsTUFBWSxPQUFPLFdBQU0sOEJBR3pCLENBQUMsQ0FIc0Q7QUFPdkQ7SUFjSSxZQUFZLFVBT1g7UUFkRCx3QkFBd0I7UUFDeEIsWUFBTyxHQUFXLEtBQUssQ0FBQztRQUN4QixpQkFBWSxHQUFHLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxJQUFJLENB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