Skip to main content

Module singleflight

Module singleflight 

Source
Expand description

Coalesce concurrent work that uses the same key.

While work for a key is in flight, later callers wait and clone its successful value. A completed value is not cached: the entry is removed when the work succeeds, so a non-overlapping later call executes its own function.

If the active call is cancelled or panics, a waiting caller may run its own function. try_work also lets a waiter retry after the active function returns an error. Use OnceMap instead when successful values should remain cached by key.

Structsยง

Group
A namespace that coalesces concurrent work by key.