https://github.com/code-hex/retrygroup
Package retrygroup provides synchronization, Context cancelation for groups of retry goroutines working on subtasks of a common task.
https://github.com/code-hex/retrygroup
context go golang goroutine retry synchronization
Last synced: 5 months ago
JSON representation
Package retrygroup provides synchronization, Context cancelation for groups of retry goroutines working on subtasks of a common task.
- Host: GitHub
- URL: https://github.com/code-hex/retrygroup
- Owner: Code-Hex
- Created: 2017-02-19T12:48:01.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-20T14:21:51.000Z (over 8 years ago)
- Last Synced: 2025-03-31T01:41:54.505Z (6 months ago)
- Topics: context, go, golang, goroutine, retry, synchronization
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 17
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
retrygroup
----------
[](https://godoc.org/github.com/Code-Hex/retrygroup)
Package retrygroup provides synchronization, Context cancelation for groups of retry goroutines working on subtasks of a common task.# Synopsis
```go
package mainimport (
"context"
"errors"
"fmt"
"time""github.com/Code-Hex/retrygroup"
)func main() {
ctx, cancel := context.WithCancel(context.Background())
g, _ := retrygroup.WithContext(ctx)
g.EnableBackoff()go func() {
<-time.After(16 * time.Second)
if cancel != nil {
fmt.Println("Finish!!")
cancel()
}
}()g.RetryGo(3, func(i int) error {
fmt.Printf("Hello: %d\n", i)
return errors.New("Try error")
})g.RetryGo(-1, func(i int) error {
fmt.Println("Never!!")
return errors.New("Try never error")
})g.Wait()
}
```
See [eg](https://github.com/Code-Hex/retrygroup/tree/master/eg)