2016-05-04 02:28:50 +00:00
|
|
|
"use strict";
|
2016-07-31 22:53:27 +00:00
|
|
|
const plugins = require("./taskbuffer.plugins");
|
|
|
|
const helpers = require("./taskbuffer.classes.helpers");
|
|
|
|
class Task {
|
|
|
|
constructor(optionsArg) {
|
2016-08-01 14:10:00 +00:00
|
|
|
// initialize by default
|
2016-08-01 11:17:15 +00:00
|
|
|
this.running = false;
|
2016-08-01 14:10:00 +00:00
|
|
|
this.bufferRunner = new helpers.BufferRunner(this);
|
|
|
|
this.cycleCounter = new helpers.CycleCounter(this);
|
2016-08-01 11:17:15 +00:00
|
|
|
this.idle = true;
|
2017-02-15 21:52:29 +00:00
|
|
|
this._state = 'ready';
|
|
|
|
let options = optionsArg;
|
2016-08-02 09:09:42 +00:00
|
|
|
this.taskFunction = optionsArg.taskFunction;
|
2016-05-04 02:28:50 +00:00
|
|
|
this.preTask = options.preTask;
|
|
|
|
this.afterTask = options.afterTask;
|
2016-08-01 14:10:00 +00:00
|
|
|
this.idle = !this.running;
|
2016-05-05 16:36:31 +00:00
|
|
|
this.buffered = options.buffered;
|
2016-08-01 14:10:00 +00:00
|
|
|
this.bufferRunner.setBufferMax(options.bufferMax);
|
2016-05-14 21:24:11 +00:00
|
|
|
this.name = options.name;
|
2016-05-04 02:28:50 +00:00
|
|
|
}
|
2016-08-01 11:17:15 +00:00
|
|
|
/**
|
|
|
|
* trigger the task. Will trigger buffered if this.buffered is true
|
|
|
|
*/
|
2016-08-02 09:09:42 +00:00
|
|
|
trigger(x) {
|
2016-05-05 17:21:50 +00:00
|
|
|
if (this.buffered) {
|
2016-08-02 09:09:42 +00:00
|
|
|
return this.triggerBuffered(x);
|
2016-05-05 17:21:50 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-08-02 09:09:42 +00:00
|
|
|
return this.triggerUnBuffered(x);
|
2016-05-05 17:21:50 +00:00
|
|
|
}
|
|
|
|
;
|
2016-07-31 22:53:27 +00:00
|
|
|
}
|
2016-05-04 02:28:50 +00:00
|
|
|
;
|
2016-08-01 11:17:15 +00:00
|
|
|
/**
|
|
|
|
* trigger task unbuffered.
|
|
|
|
*/
|
2016-08-02 09:09:42 +00:00
|
|
|
triggerUnBuffered(x) {
|
|
|
|
return helpers.runTask(this, { x: x });
|
2016-07-31 22:53:27 +00:00
|
|
|
}
|
2016-08-01 11:17:15 +00:00
|
|
|
/**
|
|
|
|
* trigger task buffered.
|
|
|
|
*/
|
2016-08-02 09:09:42 +00:00
|
|
|
triggerBuffered(x) {
|
|
|
|
return this.bufferRunner.trigger(x);
|
2016-07-31 22:53:27 +00:00
|
|
|
}
|
|
|
|
get state() {
|
|
|
|
return this._state;
|
|
|
|
}
|
|
|
|
set state(stateArg) {
|
2017-02-15 21:52:29 +00:00
|
|
|
if (stateArg === 'locked') {
|
|
|
|
this._state = 'locked';
|
2016-07-31 22:53:27 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-02-15 21:52:29 +00:00
|
|
|
plugins.beautylog.error('state type ' + stateArg + ' could not be set');
|
2016-07-31 22:53:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-04 02:28:50 +00:00
|
|
|
exports.Task = Task;
|
2017-02-15 21:52:29 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMudGFzay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsZ0RBQStDO0FBQy9DLHdEQUF1RDtBQU12RDtJQWNFLFlBQVksVUFPWDtRQWRELHdCQUF3QjtRQUN4QixZQUFPLEdBQVksS0FBSyxDQUFBO1FBQ3hCLGlCQUFZLEdBQUcsSUFBSSxPQUFPLENBQUMsWUFBWSxDQUFDLElBQUksQ0FBQyxDQUFBO1FBQzdDLGlCQUFZLEdBQUcsSUFBS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