Skip to content

feat: coalesce: single flight async call deduplication - #1921

Open
hazrid93 wants to merge 1 commit into
toss:mainfrom
hazrid93:hazrid93/80_1608
Open

feat: coalesce: single flight async call deduplication#1921
hazrid93 wants to merge 1 commit into
toss:mainfrom
hazrid93:hazrid93/80_1608

Conversation

@hazrid93

Copy link
Copy Markdown

Closes #1608.

Add coalesce(key, fn): if a call with key is already in flight, return its promise; otherwise run fn() and store the promise so concurrent callers await the same result. The entry is removed once the promise settles (later calls re run fn). fn is invoked on a microtask AFTER the entry is stored, so a re entrant coalesce(key, …) inside fn returns the stored promise instead of re running fn and racing: the robustness the issue asks for.

@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
es-toolkit Ready Ready Preview, Comment Jul 20, 2026 11:17am

Request Review

Closes toss#1608.

Add coalesce(key, fn): if a call with `key` is already in flight, return its promise; otherwise run `fn()` and store the promise so concurrent callers await the same result. The entry is removed once the promise settles (later calls re run fn). fn is invoked on a microtask AFTER the entry is stored, so a re entrant coalesce(key, …) inside fn returns the stored promise instead of re running fn and racing: the robustness the issue asks for.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: coalesce (single-flight) utility

1 participant