重试政策(Policy)

interface RetryPolicy

Decides whether to retry a failed operation, and how long to wait first.

One policy may serve many concurrent operations, so implementations must be thread-safe and should return quickly without blocking. Java implementations extend BaseMillisRetryPolicy, since Java cannot return a Duration.

Inheritors

函数

Link copied to clipboard
abstract fun nextRetryDelay(failedAttempts: Int): Duration

该函数返回在下一次尝试之前需要等待的延迟时间(单位:秒)。 failedAttempts 尝试已经失败,该函数只有在其他所有尝试都失败后才会被调用。 shouldRetry 返回了 true如果延迟时间为零或负数,则会立即重新尝试(即立即再次执行该操作)。 Duration.INFINITE 会一直等待,直到尝试重试的协程被取消为止。

Link copied to clipboard
abstract fun shouldRetry(failure: Exception, failedAttempts: Int): Boolean

返回一个布尔值,表示是否需要重试一次。 failedAttempts 至少有 1 次尝试失败了,最后一次尝试的具体情况是……(此处应填写最后一次尝试的详细信息)。 失败;故障.