promise util with propagate cancellation options

This commit is contained in:
WhatCats
2024-04-06 13:55:50 +02:00
parent 5bbcfdc9b3
commit 8ba023c04a
10 changed files with 330 additions and 142 deletions

View File

@@ -55,12 +55,14 @@ public interface Promise<T> {
<V> @NotNull Promise<V> thenComposeAsync(@NotNull ExceptionalFunction<T, Promise<V>> task);
@NotNull Promise<T> logExceptions(@NotNull String message);
@NotNull Promise<Void> erase();
default @NotNull Promise<T> logExceptions() {
return logExceptions("Exception caught in promise chain");
}
@NotNull Promise<T> logExceptions(@NotNull String message);
@NotNull Promise<T> addListener(@NotNull PromiseListener<T> listener);
@NotNull Promise<T> addListener(@Nullable Consumer<T> successHandler, @Nullable Consumer<Throwable> errorHandler);
@@ -73,30 +75,26 @@ public interface Promise<T> {
@NotNull Promise<T> onCancel(@NotNull Consumer<CancellationException> listener);
@Deprecated
@NotNull Promise<T> timeout(long time, @NotNull TimeUnit unit);
@Deprecated
default @NotNull Promise<T> timeout(long ms) {
return timeout(ms, TimeUnit.MILLISECONDS);
}
@NotNull Promise<T> maxWaitTime(long time, @NotNull TimeUnit unit);
@Deprecated
@NotNull Promise<T> timeout(long time, @NotNull TimeUnit unit);
default @NotNull Promise<T> maxWaitTime(long ms) {
return maxWaitTime(ms, TimeUnit.MILLISECONDS);
}
void addChild(@NotNull Promise<?> child);
void propagateResult(@NotNull Promise<T> target);
void cancel(@Nullable String reason);
@NotNull Promise<T> maxWaitTime(long time, @NotNull TimeUnit unit);
default void cancel() {
cancel(null);
}
void cancel(@Nullable String reason);
void complete(@Nullable T result);
void completeExceptionally(@NotNull Throwable result);