Skip to content

Instantly share code, notes, and snippets.

@purplefox
Last active April 23, 2017 09:27
Show Gist options
  • Save purplefox/1a1d8dfddd04a2b2733c2062fb9fbbba to your computer and use it in GitHub Desktop.
Save purplefox/1a1d8dfddd04a2b2733c2062fb9fbbba to your computer and use it in GitHub Desktop.
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