"use strict"; /// 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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIuY2xhc3Nlcy50YXNrLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDNUMsSUFBWSxPQUFPLFdBQU0sc0JBQ3pCLENBQUMsQ0FEOEM7QUFDL0MsSUFBWSxPQUFPLFdBQU0sOEJBR3pCLENBQUMsQ0FIc0Q7QUFHdkQ7SUFhSSxjQUFZLFVBQWlHO1FBQ3pHLEVBQUUsQ0FBQyxDQUFDLENBQUMsVUFBVSxDQUFDLENBQUEsQ0FBQztZQUFBLFVBQVUsR0FBRyxFQUFDLFlBQVksRUFBQyxjQUFXLENBQUMsRUFBQyxDQUFBO1FBQUEsQ0FBQztRQUMxRCxJQUFJLE9BQU8sR0FBRyxVQUFVLENBQUM7UUFDekIsSUFBSSxDQUFDLElBQUks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