taskbuffer/dist/taskbuffer.classes.task.js

65 lines
7.0 KiB
JavaScript
Raw Normal View History

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 () {
function Task(optionsArg) {
if (!optionsArg) {
optionsArg = { taskFunction: function () { } };
}
2016-05-04 02:28:50 +00:00
var options = optionsArg;
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;
this.buffered = options.buffered;
2016-05-05 17:21:50 +00:00
this.bufferMax = options.bufferMax;
this.name = options.name;
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;
//# sourceMappingURL=data:application/json;charset=utf8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