by blensor · 1y ago · 0 comments
I personally find the original code just as if not more readable than the static lookup table and I don't need to count out the elements if I want to know how often it will retry.
But more importantly, changing the max retries is trivial in the original code and tedious in the static lookup table, especially for bigger changes.
Also, this is something you most likely want to make configurable to adapt to certain scenarios which is not possible with a static table
There are more reasons against it but those are the the main ones that jump at me right away
for range ExponentialBackoff(ctx) {
err := request(ctx)
if err == nil {
return nil
}
}
and if one of the callsites needs to configure the backoff then you've got something like: for range ExponentialBackoff(ctx, MaxAttempts(20), BaseDelay(5)) {
err := request(ctx)
if err == nil {
return nil
}
}If you ever feel the need to write code like that lookup table, you are working on the wrong place and you have a hiring problem.