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 ¶
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 ¶
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.
Click to show internal directories.
Click to hide internal directories.