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

io.datakernel.async.Completable Maven / Gradle / Ivy

package io.datakernel.async;

import org.jetbrains.annotations.Async;
import org.jetbrains.annotations.NotNull;

import java.util.function.Consumer;

/**
 * An abstraction over something, which successful or exceptional
 * completion at some point in the future can be listened to.
 * 

* This is a more generic and flexible abstraction over * things like completion stages, promises or futures * @param */ public interface Completable { /** * Subscribes given action to be executed * after this {@code Completable} computation completes * * @param action to be executed */ void onComplete(@Async.Schedule @NotNull Callback action); /** * Subscribes given action to be executed * after this {@code Completable} computation completes * * @param action to be executed */ default void onComplete(Runnable action) { onComplete((result, e) -> action.run()); } /** * Subscribes given action to be executed after * this {@code Completable} computation completes successfully * * @param action to be executed */ default void onResult(@NotNull Consumer action) { onComplete((result, e) -> { if (e == null) { action.accept(result); } }); } /** * Subscribes given action to be executed after * this {@code Completable} computation completes exceptionally * * @param action to be executed */ default void onException(@NotNull Consumer<@NotNull Throwable> action) { onComplete((result, e) -> { if (e != null) { action.accept(e); } }); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy