mirror of
https://github.com/tommyskeff/futur4j.git
synced 2026-01-18 07:16:45 +00:00
add toFuture method
This commit is contained in:
@@ -10,10 +10,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -438,4 +435,16 @@ public abstract class AbstractPromise<T, F> implements Promise<T> {
|
||||
return completion.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<T> toFuture() {
|
||||
CompletableFuture<T> future = new CompletableFuture<>();
|
||||
this.addDirectListener(future::complete, future::completeExceptionally);
|
||||
future.whenComplete((res, e) -> {
|
||||
if (e instanceof CancellationException) {
|
||||
this.cancel();
|
||||
}
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user