A type-safe wrapper around Go’s singleflight, powered by generics.
No more interface{}, no more unsafe type assertions 🚀
golang.org/x/sync/singleflight is awesome for deduplicating concurrent calls,
but it returns interface{}, so you end up with unsafe type assertions:
val, err, _ := g.Do("key", func() (interface{}, error) {
return fetchData(), nil
})
data := val.(MyType) // panic if wrong typeWith parachute, you get compile-time safety:
p := parachute.Group[string]{} // parachute for string results
// string
val, err, shared := p.Do("key", func() (string, error) {
return fetchData(), nil
})
fmt.Println(val) // already string ✅go get github.com/daalfox/parachute