
org.davidmoten.kool.RetryWhenBuilderSingle Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kool Show documentation
Show all versions of kool Show documentation
Streaming library supporting reuse and many operators
package org.davidmoten.kool;
import java.util.concurrent.TimeUnit;
import org.davidmoten.kool.function.Predicate;
import org.davidmoten.kool.internal.operators.stream.RetryWhen;
public final class RetryWhenBuilderSingle {
private final Single single;
private Stream delays;
private int maxRetries;
private Predicate super Throwable> predicate;
public RetryWhenBuilderSingle(Single single) {
this.single = single;
}
public RetryWhenBuilderSingle delay(long duration, TimeUnit unit) {
this.delays = Single.of(unit.toMillis(duration)).repeat();
return this;
}
public RetryWhenBuilderSingle maxRetries(int maxRetries) {
this.maxRetries = maxRetries;
return this;
}
public RetryWhenBuilderSingle delays(Stream delays, TimeUnit unit) {
this.delays = delays.map(x -> unit.toMillis(x));
return this;
}
public RetryWhenBuilderSingle isTrue(Predicate super Throwable> predicate) {
this.predicate = predicate;
return this;
}
public Single build() {
return RetryWhen.build(single.toStream(), delays, maxRetries, predicate).single();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy