Skip to content

daalfox/parachute

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

parachute 🎯

Go Reference Go Report Card

A type-safe wrapper around Go’s singleflight, powered by generics.
No more interface{}, no more unsafe type assertions 🚀


✨ Why Parachute?

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 type

With 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 ✅

📦 Installation

go get github.com/daalfox/parachute

About

wrapper around singleflight to make it typesafe

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages