https://github.com/hlts2/errgroup
provides synchronization, error propagation, and Context cancelation for groups of goroutines working on subtasks of a common task
https://github.com/hlts2/errgroup
concurrency errgroup go golang goroutine lilbraries subtask
Last synced: over 1 year ago
JSON representation
provides synchronization, error propagation, and Context cancelation for groups of goroutines working on subtasks of a common task
- Host: GitHub
- URL: https://github.com/hlts2/errgroup
- Owner: hlts2
- License: mit
- Created: 2021-01-19T14:48:56.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-20T10:53:10.000Z (about 5 years ago)
- Last Synced: 2025-01-20T08:09:46.737Z (over 1 year ago)
- Topics: concurrency, errgroup, go, golang, goroutine, lilbraries, subtask
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# errgroup
[](https://goreportcard.com/report/github.com/hlts2/errgroup)
[](http://godoc.org/github.com/hlts2/errgroup)
Provide synchronization, error propagation, and Context cancelation for groups of goroutines working on subtasks of a common task.
This package highly inspired by [errgroup](https://github.com/golang/sync/tree/master/errgroup).
## Requirement
Go 1.15
## Installing
```
go get github.com/hlts2/errgroup
```
## Example
```go
package main
import (
"fmt"
"net/http"
"github.com/hlts2/errgroup"
)
func main() {
var urls = []string{
"http://www.golang.org/",
"http://www.google.com/",
"http://www.somestupidname.com/",
}
eg := new(errgroup.Group)
for _, url := range urls {
url := url
eg.Go(func() error {
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
return nil
})
}
err := eg.Wait()
if err != nil {
if err, ok := err.(errgroup.Error); ok {
fmt.Println(err.Errors()) // slice of errors that occurred inside eg.Go
}
} else {
fmt.Println("Successfully fetched all URLs.")
}
}
```
## Contribution
1. Fork it ( https://github.com/hlts2/errgroup/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create new Pull Request
## Author
[hlts2](https://github.com/hlts2)