Documentation
¶
Overview ¶
Package dedup provides a generic type-safe wrapper around golang.org/x/sync/singleflight. When multiple goroutines call Do with the same key concurrently, only the first caller executes the function — subsequent callers block until the first completes and receive the same result.
This is useful for preventing duplicate parallel tool calls from LLMs that sometimes emit the same function call multiple times in one response.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group[T any] struct { // contains filtered or unexported fields }
Group is a generic singleflight group parameterized by the result type T. Zero value is ready to use.
func (*Group[T]) Do ¶
Do executes fn exactly once for a given key, even if called concurrently from multiple goroutines.
The first caller with a given key runs fn. All subsequent callers with the same key block until fn completes, then receive the same (val, err).
The third return value "shared" is true when the result was produced by an earlier call (i.e. this caller was a duplicate).
After fn completes, the key is removed so future calls can execute again.