65 lines
7.0 KiB
JavaScript
65 lines
7.0 KiB
JavaScript
"use strict";
|
|
/// <reference path="./typings/main.d.ts" />
|
|
var plugins = require("./taskbuffer.plugins");
|
|
var helpers = require("./taskbuffer.classes.helpers");
|
|
var Task = (function () {
|
|
function Task(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;
|
|
}
|
|
Task.prototype.trigger = function () {
|
|
var done = plugins.Q.defer();
|
|
if (this.buffered) {
|
|
this.triggerBuffered()
|
|
.then(done.resolve);
|
|
}
|
|
else {
|
|
this.triggerUnBuffered()
|
|
.then(done.resolve);
|
|
}
|
|
;
|
|
return done.promise;
|
|
};
|
|
;
|
|
Task.prototype.triggerUnBuffered = function () {
|
|
return helpers.runTask(this);
|
|
};
|
|
Task.prototype.triggerBuffered = function () {
|
|
var done = plugins.Q.defer();
|
|
if (!(this.bufferCounter >= this.bufferMax)) {
|
|
this.bufferCounter++;
|
|
}
|
|
helpers.runBufferedTask(this);
|
|
return done.promise;
|
|
};
|
|
Object.defineProperty(Task.prototype, "state", {
|
|
get: function () {
|
|
return this._state;
|
|
},
|
|
set: function (stateArg) {
|
|
if (stateArg == "locked") {
|
|
this._state = "locked";
|
|
}
|
|
else {
|
|
plugins.beautylog.error("state type " + stateArg.blue + " could not be set");
|
|
}
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
return Task;
|
|
}());
|
|
exports.Task = Task;
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIuY2xhc3Nlcy50YXNrLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOi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