UNPKG

@xlink-network/xlink-sdk

Version:
61 lines (60 loc) 1.97 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/utils/pMemoize.ts var pMemoize_exports = {}; __export(pMemoize_exports, { pMemoize: () => pMemoize }); module.exports = __toCommonJS(pMemoize_exports); function pMemoize(options, fn) { const cache = /* @__PURE__ */ new Map(); const skipCache = options.skipCache == null ? async () => false : typeof options.skipCache === "function" ? options.skipCache : async () => options.skipCache; return async function(...args) { const key = options.cacheKey(args); if (cache.has(key)) { return cache.get(key); } const promise = (async () => { const cleanCache = () => { queueMicrotask(() => { if (cache.get(key) === promise) { cache.delete(key); } }); }; try { const result = await fn(...args); if (await skipCache(args, result)) { cleanCache(); } return result; } catch (e) { cleanCache(); throw e; } })(); cache.set(key, promise); return promise; }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { pMemoize }); //# sourceMappingURL=pMemoize.js.map