Skip to content

Experimental functionality #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: v5
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ See more details [here][cli].

<p align="right">made with ❤️ for everyone</p>

[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
Expand All @@ -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
17 changes: 12 additions & 5 deletions exp/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down