Created
February 20, 2022 09:05
-
-
Save shanenoi/8007aec190906a1ce832435f64330eaa to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"fmt" | |
) | |
type Retryer func() (bool, error) | |
func Do(retryNumber uint32, fn Retryer) error { | |
isRepeat := true | |
err := (error)(nil) | |
for retryNumber > 0 && isRepeat { | |
isRepeat, err = fn() | |
retryNumber-- | |
} | |
return err | |
} | |
func main() { | |
fmt.Print("hello world") | |
a := 2 | |
Do(3, func() (bool, error) { | |
fmt.Println("try") | |
if a == 1 { | |
return false, nil | |
} | |
return true, nil | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment