https://github.com/serkodev/singleflight-any
Go singleflight with generics key & value
https://github.com/serkodev/singleflight-any
concurrency generics go golang singleflight
Last synced: about 1 year ago
JSON representation
Go singleflight with generics key & value
- Host: GitHub
- URL: https://github.com/serkodev/singleflight-any
- Owner: serkodev
- License: bsd-3-clause
- Created: 2022-02-19T10:32:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-02-19T10:39:26.000Z (over 4 years ago)
- Last Synced: 2025-06-22T01:45:24.940Z (about 1 year ago)
- Topics: concurrency, generics, go, golang, singleflight
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# singleflight-any
This repo hard forks from [golang.org/x/sync/singleflight](https://pkg.go.dev/golang.org/x/sync/singleflight) and support generics to the Group and Key type. Comparing to the original version of singleflight, you are free to use any `comparable` key type instead of `string` only.
## Install
```
go get github.com/serkodev/singleflight-any@latest
```
## Usage
`string` key, `string` value
```golang
var g Group[string, string]
v, _, _ := g.Do("foo", func() (string, error) {
return "bar", nil
})
```
`int` key, `string` value
```golang
var g Group[int, string]
v, _, _ := g.Do(123, func() (string, error) {
return "bar", nil
})
```
## Requirements
go 1.18 or above.