- edited description
Generalized retry function
Issue #4
new
A helper function for flexible retrying is proposed, rather than just retrying every N seconds or M attempts.
For example, the following pattern appears frequently in our code base.
for {
err = before()
if err != nil {
time.Sleep(retryTime)
continue
}
after()
}
Such code would be replaced with the following:
for {
retry(before, after, policy)
}
The policy would describe the retry policy to be implemented and would permit more flexible retry policies than simply trying again after waiting for a period fo time, e.g.,
type RetryPolicy struct {
wait time.Duration // Wait time between retries.
retries int // Maximum number of retries, or 0 for forever.
exponential bool // True for exponential backoff.
}
The before/after functions could be anonymous functions.
Comments (2)
-
reporter -
I think having a
[]func(<some meaningful set of parameters) error
would probably be the approach I'd use here. Looking at the docs for iptables would likely be helpful for inspiration. - Log in to comment