Last active
April 23, 2017 09:27
-
-
Save purplefox/1a1d8dfddd04a2b2733c2062fb9fbbba to your computer and use it in GitHub Desktop.
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 characters
AsyncResCF<String> ar = new AsyncResCF<>(); | |
vertx.executeBlocking(fut -> { | |
// Your blocking code in here | |
}, ar); | |
ar.whenComplete((s, t) -> { | |
// CF callbacks will be always be called on the correct Vert.x thread, no need to worry about | |
// fork-join pools or anything like that | |
}); | |
// AsyncResCF is a simple utility class for adapting Handler<AsyncResult> and CompletableFuture: | |
public class AsyncResCF<T> extends CompletableFuture<T> implements Handler<AsyncResult<T>> { | |
@Override | |
public void handle(AsyncResult<T> ar) { | |
if (ar.succeeded()) { | |
complete(ar.result()); | |
} else { | |
completeExceptionally(ar.cause()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment