Kevin2566
Kevin2566

Reputation: 441

How to do retries in Kotlin, with timeout durations and maximum retry durations defined by arguments?

The codebase I'm working with already has a way of defining retry limits through annotations, e.g.

@Retry(
    retryInterval = 60
)
fun doSomething(args: ...)

However the retry parameters need to be specified as function arguments, so the function caller can set them. I don't believe this is possible with annotations as the values must be set at compile time.

I need to retry while letting the function caller define the maximum retry interval (how long to retry for before timing out), and the retry interval (how frequently it is allowed to retry)

This is likely possible with while true and wait loops, but is there a more conventional method?

Upvotes: -1

Views: 38

Answers (1)

bmargulies
bmargulies

Reputation: 99993

You will need to examine the source code of the annotation processor for @Retry. You will find that there are functions under there, and that the result of the @Retry is to wrap the written function in a call to the implementation -- which takes the parameters as ordinary parameters, just as you would like.

Upvotes: 0

Related Questions