T
- Type of outputpublic final class Retry<T> extends Object implements Scalar<T>
new RetryScalar<>(
() -> {
if (new SecureRandom().nextDouble() > 0.3d) {
throw new IllegalArgumentException("May happen");
}
return 0;
},
5
).value() // will try to run 5 times before throwing an exception
There is no thread-safety guarantee.
This class implements Scalar
, which throws a checked
Exception
. This may not be convenient in many cases. To make
it more convenient and get rid of the checked exception you can
use the Unchecked
decorator. Or you may use
IoChecked
to wrap it in an IOException.
Constructor and Description |
---|
Retry(Scalar<T> scalar)
Ctor.
|
Retry(Scalar<T> scalar,
Duration wait)
Ctor.
|
Retry(Scalar<T> scalar,
Func<Integer,Boolean> exit)
Ctor.
|
Retry(Scalar<T> scalar,
Func<Integer,Boolean> exit,
Duration wait)
Ctor.
|
Retry(Scalar<T> scalar,
int attempts)
Ctor.
|
Retry(Scalar<T> scalar,
int attempts,
Duration wait)
Ctor.
|
public Retry(Scalar<T> scalar, Duration wait)
scalar
- Scalar originalwait
- The Duration
to wait between attemptspublic Retry(Scalar<T> scalar, int attempts)
scalar
- Scalar originalattempts
- Maximum number of attemptspublic Retry(Scalar<T> scalar, int attempts, Duration wait)
scalar
- Scalar originalattempts
- Maximum number of attemptswait
- The Duration
to wait between attemptspublic Retry(Scalar<T> scalar, Func<Integer,Boolean> exit)
scalar
- Func originalexit
- Exit condition, returns TRUE if there is no reason to tryCopyright © 2017–2020 Cactoos. All rights reserved.