// Metro module 1163 (f1164). import _classCallCheck from "./_classCallCheck"; import _createClass from "./_createClass"; let env966 = {}; const AsyncExpiringMap = function AsyncExpiringMap(r3 = {}) { const { cleanupInterval = 5000, ttl: ttl2 = 2000 } = r3; _classCallCheck(this, AsyncExpiringMap); this._ttl = ttl2; this._map = new Map(); this._cleanupIntervalMs = cleanupInterval; this.startCleanup(); }; exports.AsyncExpiringMap = _createClass(AsyncExpiringMap, [{ key: "set", value: function set(a0, a1) { let c24264_0; if (!this._cleanupInterval) { this.startCleanup(); } if (typeof a1 === "object" && (a1 && "then" in a1)) { const r19 = { value: void 0, expiresAt: null, promise: a1 }; c24264_0 = r19; this._map.set(a0, r19); a1.then((result) => { c24264_0.value = result; c24264_0.expiresAt = Date.now() + this._ttl; c24264_0.promise = null; }, () => { c24264_0.expiresAt = Date.now() + this._ttl; c24264_0.promise = null; }); } else { this._map.set(a0, { value: a1, expiresAt: Date.now() + this._ttl, promise: null }); } } }, { key: "pop", value: function pop(a0) { const r4 = this.get(a0); this._map.delete(a0); return r4; } }, { key: "get", value: function get(a0) { let promise; const r8 = this._map.get(a0); if (r8) { if (r8.promise) { promise = r8.promise; } else { if (r8.expiresAt && r8.expiresAt <= Date.now()) { this._map.delete(a0); } promise = r8.value; } return promise; } } }, { key: "has", value: function has(a0) { const r10 = this._map.get(a0); let r11 = !!r10; if (r11) { let r13 = !!r10.promise; if (!r13) { const r14 = r10.expiresAt && r10.expiresAt <= Date.now(); let r2 = !r14; if (r14) { this._map.delete(a0); r2 = false; } r13 = r2; } r11 = r13; } return r11; } }, { key: "ttl", value: function ttl(a0) { const r6 = this._map.get(a0); if (r6?.expiresAt) { const r14 = r6.expiresAt - Date.now(); return r14 > 0 ? r14 : 0; } } }, { key: "cleanup", value: function cleanup() { const r5 = Date.now(); for (const item of this._map.entries()) { const [r34, r35] = item; if (r35.expiresAt && r35.expiresAt <= r5) { this._map.delete(r34); } } if (!this._map.size) { this.stopCleanup(); } } }, { key: "clear", value: function clear() { if (this._cleanupInterval) { clearInterval(this._cleanupInterval); } this._map.clear(); } }, { key: "stopCleanup", value: function stopCleanup() { if (this._cleanupInterval) { clearInterval(this._cleanupInterval); } } }, { key: "startCleanup", value: function startCleanup() { this._cleanupInterval = setInterval(() => this.cleanup(), this._cleanupIntervalMs); } }]);