Documentation
¶
Overview ¶
Package retry provides policy for repeating function call to handle transient errors.
Example ¶
package main
import (
"errors"
"fmt"
"time"
"github.com/Prastiwar/Go-flow/policy/retry"
)
func main() {
var errPersistentError = errors.New("persistent-error")
p := retry.NewPolicy(
retry.WithCount(2),
retry.WithWaitTimes(time.Second, 2*time.Second),
)
startedTime := time.Now()
err := p.Execute(func() error {
fmt.Println("executed after: " + time.Since(startedTime).Truncate(time.Second).String())
startedTime = time.Now()
return errPersistentError
})
fmt.Println(err == errPersistentError)
}
Output: executed after: 0s executed after: 1s executed after: 2s true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CancelPredicate ¶
CancelPredicate controls retrying continuation - return true to stop retrying and false to continue.
type Option ¶
type Option func(*policy)
func WithCancelPredicate ¶
func WithCancelPredicate(handler CancelPredicate) Option
WithCancelPredicate configures CancelPredicate to control retry continuation.
func WithCount ¶
WithCount configures how many times should retry be executed. If set to 0 function will be executed one time and no retry will occur.
func WithWaitTimes ¶
WithWaitTimes configures Waiter that works as wait times enumerator for specified waitTimes. If there is difference between retry count and wait times - it will return the edge index on exceeded attempt.
func WithWaiter ¶
WithWaiter configures Waiter function to provide program wait time before retry execution.