taskbuffer/dist/taskbuffer.classes.task.js

59 lines
3.6 KiB
JavaScript
Raw Normal View History

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;
2016-08-01 14:10:00 +00:00
this._state = "ready";
2016-05-04 02:28:50 +00:00
var options = optionsArg;
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;
this.buffered = options.buffered;
2016-08-01 14:10:00 +00:00
this.bufferRunner.setBufferMax(options.bufferMax);
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
*/
trigger(x) {
2016-05-05 17:21:50 +00:00
if (this.buffered) {
return this.triggerBuffered(x);
2016-05-05 17:21:50 +00:00
}
else {
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.
*/
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.
*/
triggerBuffered(x) {
return this.bufferRunner.trigger(x);
2016-07-31 22:53:27 +00:00
}
get state() {
return this._state;
}
set state(stateArg) {
if (stateArg == "locked") {
this._state = "locked";
}
else {
2017-01-19 16:26:35 +00:00
plugins.beautylog.error("state type " + stateArg + " could not be set");
2016-07-31 22:53:27 +00:00
}
}
}
2016-05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