avast / retry-go

Simple golang library for retry mechanism

Home Page:http://godoc.org/github.com/avast/retry-go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any plans for generic retry from 1.18?

pzartem opened this issue · comments

commented

I can implement it if you have any plan idea for it. This may reduce the amount of closure.

type retryableFunc[TRes any] func() (TRes, error)

val, res := retry.Do(......

Hi, I had thoughts about generics - but I only read this article https://planetscale.com/blog/generics-can-make-your-go-code-slower, and that doesn't sound like I want to add generics everywhere without a deeper analysis of value.

Have you please some another example where generic retry helps you?
Thanks

commented

Few issues with generics perf in that article are fixed only in 1.19. Like this

The only one possible benefit with generics I see now is that you don't need an additional closure on result variable. It's not so much to implement it.

Thanks!

1.19 is out. I vote up for this improvement.
Generics can really reduce amount of code around retryable calls.

Please take a look at #91 and tell us what you think.
thank you

It also is important to remember - that this suggestion only helps for functions that return one value. But functions could return 0, or more than 1 of them.

Counter suggestion: instead of changing retry.Do in a non-BC way, to introduce instead retry.Do1, retry.Do2, ... functions each of which returns the corresponding number of return values. Up to 5 should be fine, I guess.