Defining success

Retry needs to know what success means in the context of your Future in order to know when to retry an operation.

It does this through a generic Success[-T](pred: T => Boolean) type class, where T matches the type your Future will resolve to.

Retry looks for this definition within implicit scope of the retry.

You may wish define an application-specific definition of what "success" means for your future. You can do so by specifying the following in scope of the retry.

implicitvalperfectTen=Success[Int](_ ==10)

If your future completes with anything other than 10, it will be considered a failure and will be retried. Here's to you, tiger mom!

Success values may also be composed with and and or semantics

// will be considered a success when the preconditions of both successA and successB are metvalsuccessC= successA.and(successB)
// will be considered a success when the predconditions of either successC or successD are metvalsuccessE= successC.or(successD)

Sleep schedules

Rather than blocking a thread, retry attempts are scheduled using Timers. Your application may run within a platform that provides its own way for scheduling tasks. If an odelay.jdk.JdkTimer isn't what you're looking for, you may wish to use the odelay.Timer for netty, odelay.netty.Timer in the odelay-netty module or an odelay.twitter.TwitterTimer available in the odelay-twitter module.

See the odelay docs for defining your own timer. If none of these aren't what you're looking for, please open a pull request!

According to Policy

Retry logic is implemented in modules whose behavior vary but all produce a common interface: a retry.Policy.

Backoff

The retry.Backoff modules defines interfaces for retrying a future with a configureable pause and exponential
backoff factor.

// retry 4 times with a delay of 1 second which will be multipled// by 2 on every attemptvalfuture= retry.Backoff(4, 1.second).apply { () =>
attempt
}

When

All of the retry strategies above assume you are representing failure in your Future's result type. In cases where the
result of your future is "exceptional". You can use the When module which takes a PartialFunction of Any to Policy.

Note, The domain of the PartialFunction passed to When may cover both the exception thrown or the successful result of the future.

Suggested library usage

Since all retry modules now produce a generic interface, a retry.Policy, if you wish to write clients of services you may wish to make define
a Success for the type of that service and capture an configurable reference to a Policy so that clients may swap policies based on use case.