Pattern for deduplicating concurrent async work (from uv's codebase)
uv uses a pattern called OnceMap to deduplicate concurrent async work. It's a concurrent hashmap where each entry is either "waiting" (with a Tokio Notify handle) or "filled" (with the result).
It exposes three methods: register() to claim work, done() to store result and wake waiters, and wait() to block until ready.
The tricky part is wait(). Notify signals aren't queued, so if Task A calls notify_waiters() while Task B is between getting the handle and calling .await, Task B hangs forever. The fix is to call pin!(notify.notified()) before checking the map, which registers you as a waiter immediately so you catch the signal even during the check.