diff --git a/README.md b/README.md index f049e62..cf91b3a 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,12 @@ [![GoDoc](https://godoc.org/resenje.org/singleflight?status.svg)](https://godoc.org/resenje.org/singleflight) [![Go](https://github.com/janos/singleflight/workflows/Go/badge.svg)](https://github.com/janos/singleflight/actions?query=workflow%3AGo) -Package singleflight provides a duplicate function call suppression -mechanism similar to [golang.org/x/sync/singleflight](https://pkg.go.dev/golang.org/x/sync/singleflight) but with support -for context cancelation. The context passed to the callback function is a context that preserves all values -from the passed context but is cancelled by the singleflight only when all -awaiting caller's contexts are cancelled. +Package singleflight provides a duplicate function call suppression +mechanism similar to [golang.org/x/sync/singleflight](https://pkg.go.dev/golang.org/x/sync/singleflight) but with: + +- support for context cancelation. The context passed to the callback function is a context that preserves all values +from the passed context but is cancelled by the singleflight only when all awaiting caller's contexts are cancelled. +- support for generics. ## Installation diff --git a/singleflight.go b/singleflight.go index ff79a52..820f0e1 100644 --- a/singleflight.go +++ b/singleflight.go @@ -15,6 +15,8 @@ import ( // Group represents a class of work and forms a namespace in // which units of work can be executed with duplicate suppression. +// K is the type of the key used for deduplication, and V is +// the return value of the work function. type Group[K comparable, V any] struct { calls map[K]*call[V] // lazily initialized mu sync.Mutex // protects calls