taskbuffer/dist/taskbuffer.classes.task.js

58 lines
3.7 KiB
JavaScript
Raw Normal View History

2016-05-04 02:28:50 +00:00
"use strict";
2017-06-09 21:26:23 +00:00
Object.defineProperty(exports, "__esModule", { value: true });
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;
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-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) {
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-06-17 14:56:33 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMudGFzay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLGdEQUErQztBQUMvQyx3REFBdUQ7QUFNdkQ7SUFjRSxZQUFhLFVBT1o7UUFkRCx3QkFBd0I7UUFDeEIsWUFBTyxHQUFZLEtBQUssQ0FBQTtRQUN4QixpQkFBWSxHQUFHLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQUM3QyxpQkFBWSxHQUFHLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQUM3QyxTQUFJLEdBQVksSUFBSSxDQUFBO1FBQ1osV0FBTSxHQUFXLE9BQU8sQ0FBQTtRQVU5QixJQUFJLE9BQU8sR0FBRyxVQUFVLENBQUE7UUFDeEIsSUFBSSxDQUFDLFlBQVksR0FBRyxVQUFVLENBQUMsWUFBWSxDQUFBO1FBQzNDLElBQUksQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQTtRQUM5QixJQUFJLENBQUMsU0FBUyxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUE7UUFDbEMsSUFBSSxDQUFDLElBQUksR0FBRyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7UUFDekIsSUFBSSxDQUFDLFFBQVEsR0FBRyxPQUFPLENBQUMsUUFBUSxDQUFBO1FBQ2hDLElBQUksQ0FBQyxZQUFZLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FBQTtR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