2016-05-04 02:28:50 +00:00
|
|
|
"use strict";
|
|
|
|
/// <reference path="./typings/main.d.ts" />
|
|
|
|
var plugins = require("./taskbuffer.plugins");
|
|
|
|
var helpers = require("./taskbuffer.classes.helpers");
|
|
|
|
var Task = (function () {
|
2016-05-05 16:36:31 +00:00
|
|
|
function Task(optionsArg) {
|
|
|
|
if (!optionsArg) {
|
|
|
|
optionsArg = { taskFunction: function () { } };
|
|
|
|
}
|
2016-05-04 02:28:50 +00:00
|
|
|
var options = optionsArg;
|
2016-05-05 16:36:31 +00:00
|
|
|
this.task = optionsArg.taskFunction;
|
2016-05-04 02:28:50 +00:00
|
|
|
this.preTask = options.preTask;
|
|
|
|
this.afterTask = options.afterTask;
|
|
|
|
this.running = false;
|
2016-05-06 00:05:45 +00:00
|
|
|
this.idle = true;
|
2016-05-05 16:36:31 +00:00
|
|
|
this.buffered = options.buffered;
|
2016-05-05 17:21:50 +00:00
|
|
|
this.bufferMax = options.bufferMax;
|
2016-05-04 02:28:50 +00:00
|
|
|
}
|
|
|
|
Task.prototype.trigger = function () {
|
|
|
|
var done = plugins.Q.defer();
|
2016-05-05 17:21:50 +00:00
|
|
|
if (this.buffered) {
|
2016-05-06 00:05:45 +00:00
|
|
|
this.triggerBuffered()
|
|
|
|
.then(done.resolve);
|
2016-05-05 17:21:50 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-05-06 00:05:45 +00:00
|
|
|
this.triggerUnBuffered()
|
|
|
|
.then(done.resolve);
|
2016-05-05 17:21:50 +00:00
|
|
|
}
|
|
|
|
;
|
2016-05-06 00:05:45 +00:00
|
|
|
return done.promise;
|
2016-05-04 02:28:50 +00:00
|
|
|
};
|
|
|
|
;
|
2016-05-05 17:21:50 +00:00
|
|
|
Task.prototype.triggerUnBuffered = function () {
|
|
|
|
return helpers.runTask(this);
|
|
|
|
};
|
2016-05-04 02:28:50 +00:00
|
|
|
Task.prototype.triggerBuffered = function () {
|
|
|
|
var done = plugins.Q.defer();
|
2016-05-05 17:21:50 +00:00
|
|
|
if (!(this.bufferCounter >= this.bufferMax)) {
|
|
|
|
this.bufferCounter++;
|
|
|
|
}
|
|
|
|
helpers.runBufferedTask(this);
|
|
|
|
return done.promise;
|
2016-05-04 02:28:50 +00:00
|
|
|
};
|
|
|
|
Object.defineProperty(Task.prototype, "state", {
|
|
|
|
get: function () {
|
|
|
|
return this._state;
|
|
|
|
},
|
|
|
|
set: function (stateArg) {
|
|
|
|
if (stateArg == "locked") {
|
|
|
|
this._state = "locked";
|
|
|
|
}
|
|
|
|
else {
|
2016-05-06 00:05:45 +00:00
|
|
|
plugins.beautylog.error("state type " + stateArg.blue + " could not be set");
|
2016-05-04 02:28:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
return Task;
|
|
|
|
}());
|
|
|
|
exports.Task = Task;
|
|
|
|
|
2016-05-06 00:05:45 +00:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIuY2xhc3Nlcy50YXNrLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDNUMsSUFBWSxPQUFPLFdBQU0sc0JBQ3pCLENBQUMsQ0FEOEM7QUFDL0MsSUFBWSxPQUFPLFdBQU0sOEJBR3pCLENBQUMsQ0FIc0Q7QUFHdkQ7SUFZSSxjQUFZLFVBQWlHO1FBQ3pHLEVBQUUsQ0FBQyxDQUFDLENBQUMsVUFBVSxDQUFDLENBQUEsQ0FBQztZQUFBLFVBQVUsR0FBRyxFQUFDLFlBQVksRUFBQyxjQUFXLENBQUMsRUFBQyxDQUFBO1FBQUEsQ0FBQztRQUMxRCxJQUFJLE9BQU8sR0FBRyxVQUFVLENBQUM7UUFDekIsSUFBSSxDQUFDLElBQUksR0FBRyxVQUFVLENBQUMsWUFBWSxDQUFDO1FBQ3BDLElBQUksQ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