Created
March 22, 2020 22:29
-
-
Save pluttrell/9f4d3746e5715e2a56238bcc4e1a13c6 to your computer and use it in GitHub Desktop.
Revisions
-
pluttrell created this gist
Mar 22, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ public static <T> Mono<T> fromFuture(Supplier<CompletableFuture<T>> completableFutureSupplier) { return Mono.subscriberContext() .flatMap(context -> Mono.fromFuture(completableFutureSupplier) .subscriberContext(context) .doFinally(signalType -> { var completableFuture = completableFutureSupplier.get(); if (SignalType.CANCEL == signalType) { if (!completableFuture.isDone() && !completableFuture.isCancelled()) { completableFuture.cancel(true); } } }) ); }