package dev.tommyjs.futur.promise; import dev.tommyjs.futur.function.ExceptionalConsumer; import dev.tommyjs.futur.function.ExceptionalFunction; import dev.tommyjs.futur.function.ExceptionalRunnable; import dev.tommyjs.futur.function.ExceptionalSupplier; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; public interface Promise { static @NotNull Promise resolve(T value, PromiseFactory factory) { return factory.resolve(value); } static @NotNull Promise error(Throwable error, PromiseFactory factory) { return factory.error(error); } static @NotNull Promise unresolved(PromiseFactory factory) { return factory.unresolved(); } static @NotNull Promise start(PromiseFactory factory) { return factory.resolve(null); } PromiseFactory getFactory(); T join(long interval, long timeout) throws TimeoutException; @NotNull Promise thenRunSync(@NotNull ExceptionalRunnable task); @NotNull Promise thenRunDelayedSync(@NotNull ExceptionalRunnable task, long delay, @NotNull TimeUnit unit); @NotNull Promise thenConsumeSync(@NotNull ExceptionalConsumer task); @NotNull Promise thenConsumeDelayedSync(@NotNull ExceptionalConsumer task, long delay, @NotNull TimeUnit unit); @NotNull Promise thenSupplySync(@NotNull ExceptionalSupplier task); @NotNull Promise thenSupplyDelayedSync(@NotNull ExceptionalSupplier task, long delay, @NotNull TimeUnit unit); @NotNull Promise thenApplySync(@NotNull ExceptionalFunction task); @NotNull Promise thenApplyDelayedSync(@NotNull ExceptionalFunction task, long delay, @NotNull TimeUnit unit); @NotNull Promise thenComposeSync(@NotNull ExceptionalFunction> task); @NotNull Promise thenRunAsync(@NotNull ExceptionalRunnable task); @NotNull Promise thenRunDelayedAsync(@NotNull ExceptionalRunnable task, long delay, @NotNull TimeUnit unit); @NotNull Promise thenConsumeAsync(@NotNull ExceptionalConsumer task); @NotNull Promise thenConsumeDelayedAsync(@NotNull ExceptionalConsumer task, long delay, @NotNull TimeUnit unit); @NotNull Promise thenSupplyAsync(@NotNull ExceptionalSupplier task); @NotNull Promise thenSupplyDelayedAsync(@NotNull ExceptionalSupplier task, long delay, @NotNull TimeUnit unit); @NotNull Promise thenPopulateReference(@NotNull AtomicReference reference); @NotNull Promise thenApplyAsync(@NotNull ExceptionalFunction task); @NotNull Promise thenApplyDelayedAsync(@NotNull ExceptionalFunction task, long delay, @NotNull TimeUnit unit); @NotNull Promise thenComposeAsync(@NotNull ExceptionalFunction> task); @NotNull Promise logExceptions(); @NotNull Promise addListener(@NotNull PromiseListener listener); @NotNull Promise timeout(long time, @NotNull TimeUnit unit); @NotNull Promise timeout(long ms); void complete(@Nullable T result); void completeExceptionally(@NotNull Throwable result); boolean isCompleted(); @Nullable PromiseCompletion getCompletion(); }