64 lines
6.6 KiB
JavaScript
64 lines
6.6 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;
|
|
}
|
|
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIuY2xhc3Nlcy50YXNrLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0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