Skip to content

Instantly share code, notes, and snippets.

@MaikelVeen
Created March 6, 2022 12:16
Show Gist options
  • Save MaikelVeen/fce475525704dee426b0f25a050b33fe to your computer and use it in GitHub Desktop.
Save MaikelVeen/fce475525704dee426b0f25a050b33fe to your computer and use it in GitHub Desktop.
Using the Retry pattern
var count int
func GetPdfUrl(ctx context.Context) (string, error) {
count++
if count <= 3 {
return "", errors.New("boom")
} else {
return "https://linktopdf.com", nil
}
}
func main() {
r := Retry(GetPdfUrl, 5, 2*time.Second)
res, err := r(context.Background())
fmt.Println(res, err)
}
@GoAndroi
Copy link

@GoAndroi
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment