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,KAAK,UAAU,IAAI,GAAI,KACnB,IAGa,eAAT,GACA,KAAK,UAAU,OAAO,EAC1B,IAEJ,KAAK,YAAY,CAAE,OAAM,KAAI,YACtB,CAAE,EAEb,KAAK,WAAa,CAAC,EAAM,KAChB,IAGA,KAAK,OACN,KAAK,QAEL,KAAK,UACK,iBAAT,EAA0B,aAAe,eAAe,IAG7D,KAAK,UAAU,OAAO,GACtB,KAAK,YAAY,CAAE,OAAM,QAAK,EAElC,KAAK,WAAa,IAAM,KAAK,iBAC7B,KAAK,YAAe,IAChB,IAAK,KAAK,OACN,MAAM,IAAI,MAAM,8CAEpB,KAAK,OAAO,YAAY,EAAQ,EAEpC,KAAK,MAAM,EACf,CACA,SAAI,GACA,OAAO,KAAK,UAAY,QAAQ,KAAK,OACzC,EAEJ,QAAQ,YAAc","file":"/npm/@stream-io/worker-timer@1.2.5/dist/cjs/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@stream-io/worker-timer@1.2.5/dist/cjs/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.WorkerTimer = void 0;\nconst worker_build_1 = require(\"./worker.build\");\nclass WorkerTimer {\n    /**\n     * Constructs a new instance of WorkerTimer.\n     *\n     * @param init the init parameters.\n     */\n    constructor(init = {}) {\n        this.currentTimerId = 1;\n        this.callbacks = new Map();\n        this.fallback = false;\n        this.setup = ({ useWorker = true, name = \"@stream-io/worker-timer\", } = {}) => {\n            if (!useWorker) {\n                this.fallback = true;\n                return;\n            }\n            try {\n                const source = worker_build_1.timerWorker.src;\n                const blob = new Blob([source], {\n                    type: \"application/javascript; charset=utf-8\",\n                });\n                const script = URL.createObjectURL(blob);\n                this.worker = new Worker(script, { name });\n                this.worker.addEventListener(\"message\", (e) => {\n                    const { type, id } = e.data;\n                    if (type === \"tick\") {\n                        this.callbacks.get(id)?.();\n                    }\n                });\n            }\n            catch (err) {\n                console.error(\"Failed to create timer worker: \", err);\n                this.fallback = true;\n            }\n        };\n        this.destroy = () => {\n            this.callbacks.clear();\n            this.worker?.terminate();\n            this.worker = undefined;\n            this.fallback = false;\n        };\n        this.setInterval = (callback, timeout) => this.setTimer(\"setInterval\", callback, timeout);\n        this.clearInterval = (id) => {\n            this.clearTimer(\"clearInterval\", id);\n        };\n        this.setTimeout = (callback, timeout) => this.setTimer(\"setTimeout\", callback, timeout);\n        this.clearTimeout = (id) => {\n            this.clearTimer(\"clearTimeout\", id);\n        };\n        this.setTimer = (type, callback, timeout) => {\n            if (!this.ready) {\n                this.setup();\n            }\n            if (this.fallback) {\n                return (type === \"setTimeout\" ? setTimeout : setInterval)(callback, timeout);\n            }\n            const id = this.getTimerId();\n            this.callbacks.set(id, () => {\n                callback();\n                // Timeouts are one-off operations, so no need to keep callback reference\n                // after timer has fired\n                if (type === \"setTimeout\") {\n                    this.callbacks.delete(id);\n                }\n            });\n            this.sendMessage({ type, id, timeout });\n            return id;\n        };\n        this.clearTimer = (type, id) => {\n            if (!id) {\n                return;\n            }\n            if (!this.ready) {\n                this.setup();\n            }\n            if (this.fallback) {\n                (type === \"clearTimeout\" ? clearTimeout : clearInterval)(id);\n                return;\n            }\n            this.callbacks.delete(id);\n            this.sendMessage({ type, id });\n        };\n        this.getTimerId = () => this.currentTimerId++;\n        this.sendMessage = (message) => {\n            if (!this.worker) {\n                throw new Error(\"Cannot use timer worker before it's set up\");\n            }\n            this.worker.postMessage(message);\n        };\n        this.setup(init);\n    }\n    get ready() {\n        return this.fallback || Boolean(this.worker);\n    }\n}\nexports.WorkerTimer = WorkerTimer;\n"]}