Guest User

Untitled

a guest
Nov 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "time"
  6. "errors"
  7. )
  8.  
  9. type Func func() error
  10.  
  11. func Retry(n int, between time.Duration, f Func){
  12. var i int = 1
  13.  
  14. for {
  15. err := f()
  16. if err == nil {
  17. return
  18. }
  19.  
  20. if i == n {
  21. return
  22. }
  23.  
  24. <-time.After(between)
  25.  
  26. i++
  27. }
  28. }
  29.  
  30. func main() {
  31. f := func() error {
  32. fmt.Println("Hello, playground")
  33. return errors.New("")
  34. }
  35.  
  36. Retry(5, 3 * time.Second, f)
  37. }
Add Comment
Please, Sign In to add comment