All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.davidmoten.kool.RetryWhenBuilderSingle Maven / Gradle / Ivy

There is a newer version: 0.1.36
Show newest version
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 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 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