diff --git a/README.md b/README.md index 32c3489..01962b6 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,8 @@ See more details [here][cli].

made with ❤️ for everyone

+[awesome.page]: https://github.com/avelino/awesome-go#utilities +[awesome.icon]: https://awesome.re/mentioned-badge.svg [build.page]: https://travis-ci.com/kamilsk/retry [build.icon]: https://travis-ci.com/kamilsk/retry.svg?branch=v5 [coverage.page]: https://codeclimate.com/github/kamilsk/retry/test_coverage @@ -87,12 +89,11 @@ See more details [here][cli]. [mirror.page]: https://bitbucket.org/kamilsk/retry [mirror.icon]: https://img.shields.io/badge/mirror-bitbucket-blue -[awesome.page]: https://github.com/avelino/awesome-go#utilities -[awesome.icon]: https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg - [Avito]: https://tech.avito.ru/ [breaker]: https://github.com/kamilsk/breaker [cli]: https://github.com/octolab/try [context]: https://pkg.go.dev/context [Lazada]: https://github.com/lazada [Rican7/retry]: https://github.com/Rican7/retry + +[_]: https://img.shields.io/sourcegraph/rrc/github.com/kamilsk/retry diff --git a/exp/experimental.go b/exp/experimental.go index bc00be4..dd37e73 100644 --- a/exp/experimental.go +++ b/exp/experimental.go @@ -21,14 +21,21 @@ type Breaker = interface { // ErrorHandler defines a function that CheckError calls // to determine whether it should make the next attempt or not. +// // Returning true allows for the next attempt to be made. // Returning false halts the retrying process and returns the last error // returned by the called Action. type ErrorHandler = func(error) bool // CheckError creates a Strategy that checks an error and returns -// if an error is retriable or not. Otherwise, it returns the defaults. -func CheckError(handlers ...func(error) bool) func(Breaker, uint, error) bool { +// if an error is retriable or not. Otherwise, it calls the handlers +// and delegates a decision to their result with fail-fast strategy. +// +// For example, +// +// +// +func CheckError(fallback ...ErrorHandler) func(Breaker, uint, error) bool { // equal to go.octolab.org/errors.Retriable type retriable interface { error @@ -42,7 +49,7 @@ func CheckError(handlers ...func(error) bool) func(Breaker, uint, error) bool { if err, is := err.(retriable); is { return err.Retriable() } - for _, handle := range handlers { + for _, handle := range fallback { if !handle(err) { return false } @@ -51,9 +58,9 @@ func CheckError(handlers ...func(error) bool) func(Breaker, uint, error) bool { } } -// NetworkError creates an error Handler that checks an error and returns true +// NetworkError creates an ErrorHandler that checks an error and returns true // if an error is the temporary network error. -// The Handler returns the defaults if an error is not a network error. +// It returns the defaults if an error is not a network error. func NetworkError(defaults bool) func(error) bool { return func(err error) bool { if err, is := err.(net.Error); is {