UNPKG

wireit

Version:

Upgrade your npm scripts to make them smarter and more efficient

24 lines • 609 B
/** * @license * Copyright 2022 Google LLC * SPDX-License-Identifier: Apache-2.0 */ /** * A cache for values that are asynchronously computed that ensures that we * will compute the value for each key at most once. */ export class AsyncCache { #cache = new Map(); async getOrCompute(key, compute) { let result = this.#cache.get(key); if (result === undefined) { result = compute(); this.#cache.set(key, result); } return result; } get values() { return this.#cache.values(); } } //# sourceMappingURL=async-cache.js.map