io.github.sinri.keel.facade.async.FutureForEachBreakable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Keel Show documentation
Show all versions of Keel Show documentation
A website framework with VERT.X for ex-PHP-ers, exactly Ark Framework Users.
The newest version!
package io.github.sinri.keel.facade.async;
import io.vertx.core.Future;
import javax.annotation.Nonnull;
import java.util.Iterator;
import java.util.function.BiFunction;
/**
* @since 3.2.3
*/
public class FutureForEachBreakable {
@Nonnull
private final Iterable iterable;
@Nonnull
private final BiFunction> itemProcessor;
private FutureForEachBreakable(@Nonnull Iterable iterable, @Nonnull BiFunction> itemProcessor) {
this.iterable = iterable;
this.itemProcessor = itemProcessor;
}
public static Future call(@Nonnull Iterable iterable, @Nonnull BiFunction> itemProcessor) {
return new FutureForEachBreakable<>(iterable, itemProcessor).start();
}
private Future start() {
Iterator iterator = iterable.iterator();
return KeelAsyncKit.repeatedlyCall(routineResult -> {
if (iterator.hasNext()) {
T next = iterator.next();
return this.itemProcessor.apply(next, routineResult);
} else {
routineResult.stop();
return Future.succeededFuture();
}
});
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy