All Projects → Rican7 → Retry

Rican7 / Retry

Licence: mit
A simple, stateless, functional mechanism to perform actions repetitively until successful.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Retry

waiter
Delayed iteration for polling and retries.
Stars: ✭ 17 (-95.81%)
Mutual labels:  delay, incremental, retry
Elixirretry
Simple Elixir macros for linear retry, exponential backoff and wait with composable delays
Stars: ✭ 314 (-22.66%)
Mutual labels:  delay, retry
Input Spinner
A Number-Spinner, Support keyboard operations and continuous changing.
Stars: ✭ 313 (-22.91%)
Mutual labels:  delay
Carp
Carp is a programming language designed to work well for interactive and performance sensitive use cases like games, sound synthesis and visualizations.
Stars: ✭ 4,389 (+981.03%)
Mutual labels:  functional
Pagecontroller
Infinite paging controller, scrolling through contents and title bar scrolls with a delay
Stars: ✭ 344 (-15.27%)
Mutual labels:  delay
Go Tea
Tea provides an Elm inspired functional framework for interactive command-line programs.
Stars: ✭ 329 (-18.97%)
Mutual labels:  functional
Revalidate
Elegant and composable validations
Stars: ✭ 363 (-10.59%)
Mutual labels:  functional
Coconut
Simple, elegant, Pythonic functional programming.
Stars: ✭ 3,422 (+742.86%)
Mutual labels:  functional
Handyswift
Handy Swift features that didn't make it into the Swift standard library.
Stars: ✭ 403 (-0.74%)
Mutual labels:  delay
Pampy
Pampy: The Pattern Matching for Python you always dreamed of.
Stars: ✭ 3,419 (+742.12%)
Mutual labels:  functional
Kotlin Result
A multiplatform Result monad for modelling success or failure operations.
Stars: ✭ 369 (-9.11%)
Mutual labels:  functional
Failsafe
Fault tolerance and resilience patterns for the JVM
Stars: ✭ 3,541 (+772.17%)
Mutual labels:  retry
Functional Objc
Functional operators for Objective-C
Stars: ✭ 330 (-18.72%)
Mutual labels:  functional
Nspl
Non-Standard PHP Library - functional primitives toolbox and more
Stars: ✭ 365 (-10.1%)
Mutual labels:  functional
Cloe
Cloe programming language
Stars: ✭ 398 (-1.97%)
Mutual labels:  functional
Retry
because you should never give up, at least not on the first try
Stars: ✭ 303 (-25.37%)
Mutual labels:  retry
Morphism
⚡ Type-safe data transformer for JavaScript, TypeScript & Node.js.
Stars: ✭ 336 (-17.24%)
Mutual labels:  functional
Observable
The easiest way to observe values in Swift.
Stars: ✭ 346 (-14.78%)
Mutual labels:  functional
Kotlin Flow Extensions
Extensions to the Kotlin Flow library.
Stars: ✭ 404 (-0.49%)
Mutual labels:  functional
Yalinqo
Yet Another LINQ to Objects for PHP [Simplified BSD]
Stars: ✭ 400 (-1.48%)
Mutual labels:  functional

retry

Build Status Coverage Status Go Report Card GoDoc Latest Stable Version

A simple, stateless, functional mechanism to perform actions repetitively until successful.

Project Status

This project is currently in "pre-release". While the code is heavily tested, the API may change. Vendor (commit or lock) this dependency if you plan on using it.

Install

go get github.com/Rican7/retry

Examples

Basic

retry.Retry(func(attempt uint) error {
	return nil // Do something that may or may not cause an error
})

File Open

const logFilePath = "/var/log/myapp.log"

var logFile *os.File

err := retry.Retry(func(attempt uint) error {
	var err error

	logFile, err = os.Open(logFilePath)

	return err
})

if nil != err {
	log.Fatalf("Unable to open file %q with error %q", logFilePath, err)
}

logFile.Chdir() // Do something with the file

HTTP request with strategies and backoff

var response *http.Response

action := func(attempt uint) error {
	var err error

	response, err = http.Get("https://api.github.com/repos/Rican7/retry")

	if nil == err && nil != response && response.StatusCode > 200 {
		err = fmt.Errorf("failed to fetch (attempt #%d) with status code: %d", attempt, response.StatusCode)
	}

	return err
}

err := retry.Retry(
	action,
	strategy.Limit(5),
	strategy.Backoff(backoff.Fibonacci(10*time.Millisecond)),
)

if nil != err {
	log.Fatalf("Failed to fetch repository with error %q", err)
}

Retry with backoff jitter

action := func(attempt uint) error {
	return errors.New("something happened")
}

seed := time.Now().UnixNano()
random := rand.New(rand.NewSource(seed))

retry.Retry(
	action,
	strategy.Limit(5),
	strategy.BackoffWithJitter(
		backoff.BinaryExponential(10*time.Millisecond),
		jitter.Deviation(random, 0.5),
	),
)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].