Code Monkey home page Code Monkey logo

retry-go's Introduction

retry-go

Small helper library to retry operations automatically on certain errors.

Usage

The retry package provides a Do() function which can be used to execute a provided function until it succeds.

op := func() error {
	// Do something that can fail and should be retried here
	return httpClient.CreateUserOnRemoteServer()
}
retry.Do(op, 
         retry.RetryChecker(IsNetOpErr),
         retry.Timeout(15 * time.Second))

Besides the op itself, you can provide a few options:

  • RetryChecker(func(err error) bool) - If this func returns true for the returned error, the operation is tried again (default: nil - no retries)
  • MaxTries(int) - Maximum number of calls to op() before aborting with MaxRetriesReachedErr
  • Timeout(time.Duration) - Maximum number of time to try to perform this op before aborting with TimeoutReachedErr
  • Sleep(time.Duration) - time to sleep after every failed op()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.