mirror of
https://github.com/pezkuwichain/pezkuwi-api.git
synced 2026-04-22 21:57:57 +00:00
31467f90d4
- @pezkuwi/papi-utils (rebrand of @polkadot-api/utils) - @pezkuwi/bizinikiwi-bindings (rebrand of @polkadot-api/substrate-bindings) - @pezkuwi/metadata-builders (rebrand of @polkadot-api/metadata-builders) - @pezkuwi/merkleize-metadata (rebrand of @polkadot-api/merkleize-metadata) All @polkadot-api references replaced with @pezkuwi equivalents.
20 lines
582 B
JavaScript
20 lines
582 B
JavaScript
const withCache = (fn, onEnterCircular, onExitCircular) => (input, cache, stack, ...rest) => {
|
|
const { id } = input;
|
|
if (cache.has(id)) return cache.get(id);
|
|
if (stack.has(id)) {
|
|
const res = onEnterCircular(() => cache.get(id), input, ...rest);
|
|
cache.set(id, res);
|
|
return res;
|
|
}
|
|
stack.add(id);
|
|
let result = fn(input, cache, stack, ...rest);
|
|
stack.delete(id);
|
|
if (cache.has(id))
|
|
result = onExitCircular(result, cache.get(id), input, ...rest);
|
|
cache.set(id, result);
|
|
return result;
|
|
};
|
|
|
|
export { withCache };
|
|
//# sourceMappingURL=with-cache.mjs.map
|