You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The truthiness bug I also fixed, if (cacheHit) failed for cached values like 0, "", or false. Using Map + .has() makes cache hits reliable.if (cacheHit) failed for cached values like 0, "", or false. Using Map + .has() makes cache hits reliable.
Ensure all Promise usages consistently use the injected constructor; verify that any external calls (e.g., setAsync timing) and returned promises interoperate correctly with environments that pass a custom Promise implementation.
Confirm inflight entries are always removed even if fn throws synchronously or returns a non-thenable; also validate behavior when fn resolves to undefined/falsy results and caching semantics remain correct.
setAsync uses setTimeout with a 0ms delay without a clear need; verify consumers don’t depend on synchronous cache population and consider microtask scheduling to preserve ordering with custom Promise implementations.
Deleting inflight before the async cache write introduces a race window where subsequent calls can miss both cache and inflight, causing duplicate executions. Set the cache synchronously before deleting inflight to eliminate this gap. This preserves deduplication guarantees under concurrent access.
.then((result) => {
- this.setAsync(key, result);+ // Set cache synchronously to avoid a gap that can trigger duplicate inflight requests+ this.set(key, result);
this.inflight.delete(key);
return result;
})
Apply / Chat
Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies a race condition where a key is removed from inflight before being added to cache due to setAsync. This could cause duplicate executions, defeating the purpose of the inflight map. The proposed fix is critical for correctness.
High
More
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey all,
The truthiness bug I also fixed, if (
cacheHit) failed for cached values like0, "", or false. Using Map +.has()makes cache hitsreliable.if(cacheHit) failed for cached values like0, "", or false. Using Map +.has()makes cache hits reliable.At the end of the day it still calls:
Cheers,
Michael