retry

package module
Version: v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2021 License: MIT Imports: 3 Imported by: 0

README

retry

Go Report Card Godoc Releases LICENSE

Package retry A utility to invoke a method that might fail, but should eventually succeed.

Documentation & Examples

Documentation & Examples can be found on the packages documentation.

Documentation

Overview

Package retry A utility to invoke a method that might fail, but should eventually succeed.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Try

func Try(method func() error, times int) error

Try will invoke the given method and wait for it to return. If the method returns an error it will retry up-to the specified number of attempts. If every invocation returns an error the last error is returned. If successful nil is returned.

Example
package main

import (
	"github.com/ecnepsnai/retry"
)

func main() {
	err := retry.Try(func() error {
		// Invoke a method that may initially fail, but should eventually suceed
		return nil
	}, 5)
	if err != nil {
		// After 5 attempts it never suceeded
	}
}
Output:

func TryAsync

func TryAsync(method func() error, times int, finished func(error))

TryAsync will invoke the given method asynchronously. If the method returns an error it will retry up-to the specified number of attempts. If every invocation returns an error the last error is provided in the finished callback. If successful the error is nil.

Example
package main

import (
	"github.com/ecnepsnai/retry"
)

func main() {
	retry.TryAsync(func() error {
		// Invoke a method that may initially fail, but should eventually suceed
		return nil
	}, 5, func(err error) {
		if err != nil {
			// After 5 attempts it never succeeded
		}
	})
}
Output:

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL