项目作者: Code-Hex

项目描述 :
Package retrygroup provides synchronization, Context cancelation for groups of retry goroutines working on subtasks of a common task.
高级语言: Go
项目地址: git://github.com/Code-Hex/retrygroup.git
创建时间: 2017-02-19T12:48:01Z
项目社区:https://github.com/Code-Hex/retrygroup

开源协议:

下载


retrygroup

GoDoc
Package retrygroup provides synchronization, Context cancelation for groups of retry goroutines working on subtasks of a common task.

Synopsis

  1. package main
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "time"
  7. "github.com/Code-Hex/retrygroup"
  8. )
  9. func main() {
  10. ctx, cancel := context.WithCancel(context.Background())
  11. g, _ := retrygroup.WithContext(ctx)
  12. g.EnableBackoff()
  13. go func() {
  14. <-time.After(16 * time.Second)
  15. if cancel != nil {
  16. fmt.Println("Finish!!")
  17. cancel()
  18. }
  19. }()
  20. g.RetryGo(3, func(i int) error {
  21. fmt.Printf("Hello: %d\n", i)
  22. return errors.New("Try error")
  23. })
  24. g.RetryGo(-1, func(i int) error {
  25. fmt.Println("Never!!")
  26. return errors.New("Try never error")
  27. })
  28. g.Wait()
  29. }

See eg