"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../Class/Functional");
const APINotImplementedError_1 = require("../../../../exception/APINotImplementedError");
const _ids_1 = require("../../../_ids");
class Timer extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['ms'],
            o: ['ms'],
        }, {}, system, _ids_1.ID_TIMER);
        this._timer = null;
    }
    f({ ms }, done) {
        const { api: { window: { setTimeout }, }, } = this.__system;
        if (!setTimeout) {
            throw new APINotImplementedError_1.APINotSupportedError('setTimeout');
        }
        // @ts-ignore
        this._timer = setTimeout(() => {
            this._timer = null;
            done({ ms });
        }, ms);
    }
    d() {
        const { api: { window: { clearTimeout }, }, } = this.__system;
        if (this._timer !== null) {
            clearTimeout(this._timer);
            this._timer = undefined;
        }
    }
}
exports.default = Timer;
//# sourceMappingURL=index.js.map