Xuanwo/backon

Docs can be improved a lot

Xuanwo opened this issue · 0 comments

Xuanwo commented

From reddit:

Does ExponentialBackoff's max_times and max_delay meets your need?

No.

First, the documentation could be better. "If max times is reaching" is unclear and ungrammatical. I might say "Backoff will return Some at most max_times times."

Second, what I'd want is an absolute deadline, and stopping early if the next sleep won't finish until after then. Same idea with the budget: I want a per-attempt check I want to do before the sleep, or a fallible callback to do the sleep. I could do this myself by using the Backoff as an Iterator, but then I don't get the slickness of the Retryable/BlockingRetryable traits.

backon support this feature by accepting a function notify

Oh, I missed that too, sorry! The doc could be better here too though. I might say "registers a notification to be called before waiting for a next attempt"; name the callback's parameters as previous_error and sleep_time, respectively; and amend the log message in the example to will retry after {dur:?} due to error: {err:?}". Could even have the arguments in a struct to allow adding more stuff there without callbacks needing to see stuff they're not interested in (e.g., could add attempt count).