The initial state of the policy.
The initial state of the policy. This can be an effect, such as
nanoTime
.
Invoked on an error.
Invoked on an error. This method can return the next state, which will continue the retry process, or it can return a failure, which will terminate the retry.
Extracts the value of this policy from the state.
Returns a new policy that retries for as long as this policy and the specified policy both agree to retry, using the longer of the two durations between retries.
Returns a new policy that retries for as long as this policy and the specified policy both agree to retry, using the longer of the two durations between retries.
For pure policies (which have deterministic initial states/updates), the following laws holds:
io.retryWith(r && never).void === io.retryWith(never)
io.retryWith(r && r).void === io.retryWith(r).void
io.retryWith(r1 && r2).map(t => (t._2, t._1)) === io.retryWith(r2 && r1)
The same as &&
, but discards the right hand state.
The same as &&
, but discards the left hand state.
Same as <||>
, but merges the states.
Returns a new policy that first tries this policy, and if it fails, then switches over to the specified policy.
Returns a new policy that first tries this policy, and if it fails, then switches over to the specified policy. The returned policy is maximally lazy, not computing the initial state of the alternate policy until when and if this policy fails.
io.retryWith(Retry.never <> r.void) === io.retryWith(r) io.retryWith(r.void <> Retry.never) === io.retryWith(r)
A named version of the <||>
operator.
A named alias for &&
.
The same as both
followed by map
.
Peeks at the value produced by this policy, executes some action, and then continues retrying or not based on the specified value predicate.
Returns a new retry policy that always produces the constant state.
Returns a new retry policy with the capability to handle a narrower class
of errors E2
.
Delays the retry policy by the specified amount.
A named alias for ||
.
The same as either
followed by map
.
Applies random jitter to the retry policy bounded by the specified factors.
Applies random jitter to the retry policy bounded by the factors 0.0 and 1.0.
Returns a new retry policy with the value transformed by the specified function.
Modifies the delay of this retry policy by applying the specified effectful function to the error, state, and current delay.
A new policy that applies the current one but runs the specified effect for every decision of this policy.
A new policy that applies the current one but runs the specified effect for every decision of this policy. This can be used to create retry policies that log failures, decisions, or computed values.
Modifies the duration and retry/no-retry status of this policy.
Negates this policy, returning failures for successes, and successes for failures.
Returns a new policy that retries until the error matches the condition.
Returns a new retry policy that always produces unit state.
Returns a new policy that retries while the error matches the condition.
Returns a new policy that retries for as long as either this policy or the specified policy want to retry, using the shorter of the two durations.
Returns a new policy that retries for as long as either this policy or the specified policy want to retry, using the shorter of the two durations.
For pure policies (which have deterministic initial states/updates), the following laws holds:
io.retryWith(r || always).void === io.retryWith(r)
io.retryWith(r || r).void === io.retryWith(r).void
io.retryWith(r1 || r2).map(t => (t._2, t._1)) === io.retryWith(r2 || r1)
A stateful policy for retrying
IO
actions. SeeIO.retry
.A
Retry[E, A]
value can handle errors of typeE
, and produces a value of typeA
at every step.Retry[E, A]
forms an applicative on the value, allowing rich composition of different retry policies.Retry policies also compose each of the following ways:
1. Intersection, using the
&&
operator, which requires that both policies agree to retry, using the longer of the two durations between retries. 2. Union, using the||
operator, which requires that only one policy agrees to retry, using the shorter of the two durations between retries. 3. Sequence, using the<||>
operator, which applies the first policy until it fails, and then switches over to the second policy.