"use strict"; const plugins = require("./taskbuffer.plugins"); const helpers = require("./taskbuffer.classes.helpers"); class Task { constructor(optionsArg) { // initialize by default this.running = false; this.bufferRunner = new helpers.BufferRunner(this); this.cycleCounter = new helpers.CycleCounter(this); this.idle = true; this._state = "ready"; var options = optionsArg; this.task = optionsArg.taskFunction; this.preTask = options.preTask; this.afterTask = options.afterTask; this.idle = !this.running; this.buffered = options.buffered; this.bufferRunner.setBufferMax(options.bufferMax); this.name = options.name; } /** * trigger the task. Will trigger buffered if this.buffered is true */ trigger() { let done = plugins.Q.defer(); if (this.buffered) { this.triggerBuffered() .then(done.resolve); } else { this.triggerUnBuffered() .then(done.resolve); } ; return done.promise; } ; /** * trigger task unbuffered. */ triggerUnBuffered() { return helpers.runTask(this); } /** * trigger task buffered. */ triggerBuffered() { return this.bufferRunner.trigger(); } get state() { return this._state; } set state(stateArg) { if (stateArg == "locked") { this._state = "locked"; } else { plugins.beautylog.error("state type " + stateArg.blue + " could not be set"); } } } exports.Task = Task; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMudGFzay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0sc0JBQ3pCLENBQUMsQ0FEOEM7QUFDL0MsTUFBWSxPQUFPLFdBQU0sOEJBR3pCLENBQUMsQ0FIc0Q7QUFPdkQ7SUFjSSxZQUFZLFVBT1g7UUFkRCx3QkFBd0I7UUFDeEIsWUFBTyxHQUFXLEtBQUssQ0FBQztRQUN4QixpQkFBWSxHQUFHLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsQ0FBQztRQUM5QyxpQkFBWSxHQUFHLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMs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