github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/btpmanager/credentials/utils.go (about) 1 package btpmgrcreds 2 3 import ( 4 "fmt" 5 "time" 6 ) 7 8 func CallWithRetry[T any](closure func() (T, error), maxAttempts int, retryDelay time.Duration) (T, error) { 9 doneAttempts := 0 10 for { 11 result, err := closure() 12 if err == nil { 13 return result, nil 14 } 15 doneAttempts++ 16 if doneAttempts >= maxAttempts { 17 var empty T 18 return empty, fmt.Errorf("%s. (All %d retries resulted in error)", err, maxAttempts) 19 } 20 time.Sleep(retryDelay) 21 } 22 }