T
- Type of outputpublic final class RetryScalar<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 UncheckedScalar
decorator. Or you may use
IoCheckedScalar
to wrap it in an IOException.
Constructor and Description |
---|
RetryScalar(Scalar<T> scalar)
Ctor.
|
RetryScalar(Scalar<T> scalar,
Func<Integer,Boolean> exit)
Ctor.
|
RetryScalar(Scalar<T> scalar,
int attempts)
Ctor.
|
Copyright © 2017–2019 Cactoos. All rights reserved.