UNPKG

@sebastianwessel/quickjs

Version:

A typescript package to execute JavaScript and TypeScript code in a WebAssembly QuickJS sandbox

27 lines (26 loc) 785 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createTimeInterval = void 0; /** * Utilizes the standard setInterval to work properly with javascript `using` statement. * Because of this, the interval gets automatically cleared on dispose. */ const createTimeInterval = (...params) => { const interval = { id: setInterval(...params), clear: function () { if (this.id) { clearInterval(this.id); } this.id = undefined; }, [Symbol.dispose]: function () { if (this.id) { clearInterval(this.id); } this.id = undefined; }, }; return interval; }; exports.createTimeInterval = createTimeInterval;