From 459f9ba0916eda7a52b035ed13f9ce0da572a58e Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Thu, 19 Dec 2024 14:00:03 -0600 Subject: [PATCH] Explicit async --- src/AssetCache.js | 2 +- src/RemoteAssetCache.js | 2 +- test/QueueTest.js | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/AssetCache.js b/src/AssetCache.js index 001d8e4..80f484c 100644 --- a/src/AssetCache.js +++ b/src/AssetCache.js @@ -275,7 +275,7 @@ class AssetCache { return fs.readFileSync(contentPath, type !== "buffer" ? "utf8" : null); } - getCachedContents(type) { + async getCachedContents(type) { if(!this.#rawContents[type]) { this.#rawContents[type] = this.#getCachedContents(type); } diff --git a/src/RemoteAssetCache.js b/src/RemoteAssetCache.js index 6122b7d..1244272 100644 --- a/src/RemoteAssetCache.js +++ b/src/RemoteAssetCache.js @@ -207,7 +207,7 @@ class RemoteAssetCache extends AssetCache { // async but not explicitly declared for promise equality checks // returns a Promise - fetch(optionsOverride = {}) { + async fetch(optionsOverride = {}) { if(!this.#fetchPromise) { // one at a time. clear when finished this.#fetchPromise = this.#fetch(optionsOverride).finally(() => { diff --git a/test/QueueTest.js b/test/QueueTest.js index 30fe04d..fc501ea 100644 --- a/test/QueueTest.js +++ b/test/QueueTest.js @@ -202,11 +202,9 @@ test("Raw Fetch using fetch method (check parallel fetch promise reuse)", async // Make sure the instance is the same t.is(ac1, ac2); - let fetch1 = ac1.fetch(); - let fetch2 = ac1.fetch(); - t.is(fetch1, fetch2); + let [result1, result2] = await Promise.all([ac1.fetch(), ac1.fetch()]); - t.is(await fetch1, await fetch2); + t.is(result1, result2); t.false(ac1.wasLastFetchCacheHit())