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

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

Go to download

Efficient non-blocking network and file I/O, for building Node.js-like client/server applications with high performance requirements. It is similar to Event Loop in Node.js. Although Eventloop runs in a single thread, multiple event loops can be launched at the same time allowing for efficient CPU usage.

The newest version!
package io.datakernel.async.callback;

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