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.idle = true;
|
|
|
|
this.running = false;
|
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) {
|
|
|
|
this.triggerBuffered();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.triggerUnBuffered();
|
|
|
|
}
|
|
|
|
;
|
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 {
|
|
|
|
plugins.beautylog.error("state type");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
return Task;
|
|
|
|
}());
|
|
|
|
exports.Task = Task;
|
|
|
|
|
2016-05-05 17:21:50 +00:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIuY2xhc3Nlcy50YXNrLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDNUMsSUFBWSxPQUFPLFdBQU0sc0JBQ3pCLENBQUMsQ0FEOEM7QUFDL0MsSUFBWSxPQUFPLFdBQU0sOEJBR3pCLENBQUMsQ0FIc0Q7QUFHdkQ7SUFZSSxjQUFZLFVBQWlHO1FBQ3pHLEVBQUUsQ0FBQyxDQUFDLENBQUMsVUFBVSxDQUFDLENBQUEsQ0FBQztZQUFBLFVBQVUsR0FBRyxFQUFDLFlBQVksRUFBQyxjQUFXLENBQUMsRUFBQyxDQUFBO1FBQUEsQ0FBQztRQUMxRCxJQUFJLE9BQU8sR0FBRyxVQUFVLENBQUM7UUFDekIsSUFBSSxDQUFDLElBQUksR0FBRyxVQUFVLENBQUMsWUFBWSxDQUFDO1FBQ3BDLElBQUksQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQztRQUMvQixJQUFJLENBQUMsU0FBUyxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUM7UUFDbkMsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUM7UUFDakIsSUFBSSxDQUFDLE9BQU8sR0FBRyxLQUFLLENBQUM7UUFDckIsSUFBSS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