Last active
May 24, 2017 00:39
-
-
Save nstogner/57012ef4811a2ff749a45f7c5491dcc8 to your computer and use it in GitHub Desktop.
Go: Simple retry function (usage)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Prints: A | |
retry(3, time.Second, func() error { | |
fmt.Print("A") | |
return nil | |
}) | |
// 2. Prints: BB | |
var i int | |
retry(3, time.Second, func() error { | |
i++ | |
fmt.Print("B") | |
if i == 2 { | |
return stop{errors.New("stop it")} | |
} | |
return errors.New("keep going") | |
}) | |
// 3. Prints: CCC | |
retry(3, time.Second, func() error { | |
fmt.Print("C") | |
return errors.New("not today") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage for retry function: https://gist.github.com/nstogner/6ee6c3feb97f5e8360cfe38c75f4acf8