"use strict";
/**
 * Delay event handler
 *
 *  Copyright (C) 2010-2019 R-T Specialty, LLC.
 *
 *  This file is part of the Liza Data Collection Framework
 *
 *  Liza is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.DelayEventHandler = void 0;
/**
 * Handles delay events
 */
var DelayEventHandler = /** @class */ (function () {
    /**
     * Initializes with client that will delegate the event
     *
     * @param _client - client object
     */
    function DelayEventHandler(_client) {
        this._client = _client;
    }
    /**
     * Handles Delay Events
     *
     * @param _type - event id; ignored
     * @param c     - to invoke on completion
     * @param data  - additional event data
     */
    DelayEventHandler.prototype.handle = function (_type, c, data) {
        var _this = this;
        var delay_ms = !isNaN(+data.seconds) ? +data.seconds * 1e3 : 0;
        setTimeout(function () {
            var then_action = data.then.action;
            var then_data = data.then;
            // pass along any arbitrary properties assigned to the action
            // except the action type itself
            delete then_data.action;
            _this._client.handleEvent(then_action, then_data, c);
        }, delay_ms);
        return this;
    };
    return DelayEventHandler;
}());
exports.DelayEventHandler = DelayEventHandler;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGVsYXlFdmVudEhhbmRsZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJEZWxheUV2ZW50SGFuZGxlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0FtQkc7OztBQUtIOztHQUVHO0FBQ0g7SUFDRTs7OztPQUlHO0lBQ0gsMkJBQTZC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