taskbuffer/dist/taskbuffer.classes.task.js

61 lines
3.8 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");
2016-08-03 12:51:43 +00:00
var q_1 = require("q");
exports.Promise = q_1.Promise;
2016-07-31 22:53:27 +00:00
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 {
plugins.beautylog.error("state type " + stateArg.blue + " could not be set");
}
}
}
2016-05-04 02:28:50 +00:00
exports.Task = Task;
2016-08-03 12:51:43 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMudGFzay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0sc0JBQ3pCLENBQUMsQ0FEOEM7QUFDL0MsTUFBWSxPQUFPLFdBQU0sOEJBR3pCLENBQUMsQ0FIc0Q7QUFJdkQsa0JBQXNCLEdBQUcsQ0FBQztBQUFsQiw4QkFBa0I7QUFNMUI7SUFjSSxZQUFZLFVBT1g7UUFkRCx3QkFBd0I7UUFDeEIsWUFBTyxHQUFXLEtBQUssQ0FBQztRQUN4QixpQkFBWSxHQUFHLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsQ0FBQztRQUM5QyxpQkFBWSxHQUFHLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsQ0FBQztRQUM5QyxTQUFJLEdBQVcsSUFBSSxDQUFDO1FBQ1osV0FBTSxHQUFVLE9BQU8sQ0FBQztRQVU1QixJQUFJLE9BQU8sR0FBRyxVQUFVLENBQUM7UUFDekIsSUFBSSxDQUFDLFlBQVksR0FBRyxVQUFVLENBQUMsWUFBWSxDQUFDO1FBQzVDLElBQUksQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQztRQUMvQixJQUFJLENBQUMsU0FBUyxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUM7UUFDbkMsSUFBSSxDQUFDLElBQUksR0FBRyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7UUFDMUIsSUFBSSxDQUFDLFFBQVEsR0FBRyxPQUFP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