mirror of
https://github.com/tommyskeff/futur4j.git
synced 2026-01-17 23:16:01 +00:00
handle null in compose methods
This commit is contained in:
@@ -166,12 +166,16 @@ public abstract class AbstractPromise<T, F> implements Promise<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> @NotNull Promise<V> thenComposeSync(@NotNull ExceptionalFunction<T, @NotNull Promise<V>> task) {
|
||||
public <V> @NotNull Promise<V> thenComposeSync(@NotNull ExceptionalFunction<T, Promise<V>> task) {
|
||||
Promise<V> promise = getFactory().unresolved();
|
||||
thenApplySync(task).addDirectListener(
|
||||
nestedPromise -> {
|
||||
if (nestedPromise == null) {
|
||||
promise.complete(null);
|
||||
} else {
|
||||
propagateResult(nestedPromise, promise);
|
||||
propagateCancel(promise, nestedPromise);
|
||||
}
|
||||
},
|
||||
promise::completeExceptionally
|
||||
);
|
||||
@@ -267,8 +271,12 @@ public abstract class AbstractPromise<T, F> implements Promise<T> {
|
||||
Promise<V> promise = getFactory().unresolved();
|
||||
thenApplyAsync(task).addDirectListener(
|
||||
nestedPromise -> {
|
||||
if (nestedPromise == null) {
|
||||
promise.complete(null);
|
||||
} else {
|
||||
propagateResult(nestedPromise, promise);
|
||||
propagateCancel(promise, nestedPromise);
|
||||
}
|
||||
},
|
||||
promise::completeExceptionally
|
||||
);
|
||||
|
||||
@@ -33,7 +33,7 @@ public interface Promise<T> {
|
||||
|
||||
<V> @NotNull Promise<V> thenApplyDelayedSync(@NotNull ExceptionalFunction<T, V> task, long delay, @NotNull TimeUnit unit);
|
||||
|
||||
<V> @NotNull Promise<V> thenComposeSync(@NotNull ExceptionalFunction<T, @NotNull Promise<V>> task);
|
||||
<V> @NotNull Promise<V> thenComposeSync(@NotNull ExceptionalFunction<T, Promise<V>> task);
|
||||
|
||||
@NotNull Promise<Void> thenRunAsync(@NotNull ExceptionalRunnable task);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user