https://github.com/k1low/concgroup
concgroup provides almost the same features to goroutine groups as golang.org/x/sync/errgroup but ensures sequential run of goroutines with the same group key.
https://github.com/k1low/concgroup
concurrency errgroup go
Last synced: 4 months ago
JSON representation
concgroup provides almost the same features to goroutine groups as golang.org/x/sync/errgroup but ensures sequential run of goroutines with the same group key.
- Host: GitHub
- URL: https://github.com/k1low/concgroup
- Owner: k1LoW
- License: mit
- Created: 2023-03-10T14:23:22.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-07-14T00:37:55.000Z (11 months ago)
- Last Synced: 2025-07-14T02:54:01.638Z (11 months ago)
- Topics: concurrency, errgroup, go
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# concgroup
[](https://pkg.go.dev/github.com/k1LoW/concgroup) [](https://github.com/k1LoW/concgroup/actions/workflows/ci.yml)   
`concgroup` provides almost the same features to goroutine groups as `golang.org/x/sync/errgroup` but ensures sequential run of goroutines with the same group key.
## Usage
``` go
package main
import (
"fmt"
"net/http"
"time"
"github.com/k1LoW/concgroup"
)
func main() {
cg := new(concgroup.Group)
var urlgroups = map[string][]string{
"go": {
"https://go.dev/",
"https://go.dev/dl/",
},
"google": {
"http://www.google.com/",
},
}
for key, ug := range urlgroups {
for _, url := range ug {
url := url // https://golang.org/doc/faq#closures_and_goroutines
cg.Go(key, func() error {
// Fetch URL sequentially by key
resp, err := http.Get(url)
if err == nil {
resp.Body.Close()
}
return err
})
}
}
// Wait for all HTTP fetches to complete.
if err := cg.Wait(); err == nil {
fmt.Println("Successfully fetched all URLs.")
}
}
```