我找到了一些例子
Wrapping an asynchronous computation into a synchronous (blocking) computation
但是我如何将异步方法包装到CompletableFuture
类似的东西:
RxJava2Baz baz = Single.create(new SingleOnSubscribe<Baz>() {
@Override
public void subscribe(SingleEmitter<Baz> emitter) {
doSomethingAsync(fooArg, barArg, new BazComputationSink() {
@Override
public void onBazResult(Baz result) {
emitter.onSuccess(result);
}
});
}
}).toFuture().get();