package main
import (
"context"
"fmt"
"time"
"github.com/brunotm/backoff"
)
func main() {
count := 0
err := backoff.Retry(
context.Background(), 100, 1*time.Second, 60*time.Second,
func() error {
count++
fmt.Println("Count: ", count)
if count == 5 {
return nil
}
return fmt.Errorf("op error")
})
fmt.Println(err)
}
package main
import (
"context"
"fmt"
"time"
"github.com/brunotm/backoff"
)
func main() {
count := 0
// Until only returns an error when the context is done.
err := backoff.Until(
context.Background(), 1*time.Second, 60*time.Second,
func() error {
count++
fmt.Println("Count: ", count)
if count == 5 {
return nil
}
return fmt.Errorf("op error")
})
fmt.Println(err)
}
Written by Bruno Moura [email protected]