57 lines
3.9 KiB
JavaScript
57 lines
3.9 KiB
JavaScript
"use strict";
|
|
const plugins = require("./taskbuffer.plugins");
|
|
const helpers = require("./taskbuffer.classes.helpers");
|
|
class Task {
|
|
constructor(optionsArg) {
|
|
if (!optionsArg) {
|
|
optionsArg = { taskFunction: function () { } };
|
|
}
|
|
var options = optionsArg;
|
|
this.task = optionsArg.taskFunction;
|
|
this.preTask = options.preTask;
|
|
this.afterTask = options.afterTask;
|
|
this.running = false;
|
|
this.idle = true;
|
|
this.buffered = options.buffered;
|
|
this.bufferMax = options.bufferMax;
|
|
this.name = options.name;
|
|
}
|
|
trigger() {
|
|
let done = plugins.Q.defer();
|
|
if (this.buffered) {
|
|
this.triggerBuffered()
|
|
.then(done.resolve);
|
|
}
|
|
else {
|
|
this.triggerUnBuffered()
|
|
.then(done.resolve);
|
|
}
|
|
;
|
|
return done.promise;
|
|
}
|
|
;
|
|
triggerUnBuffered() {
|
|
return helpers.runTask(this);
|
|
}
|
|
triggerBuffered() {
|
|
var done = plugins.Q.defer();
|
|
if (!(this.bufferCounter >= this.bufferMax)) {
|
|
this.bufferCounter++;
|
|
}
|
|
helpers.runBufferedTask(this);
|
|
return done.promise;
|
|
}
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMudGFzay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0sc0JBQ3pCLENBQUMsQ0FEOEM7QUFDL0MsTUFB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