Search code examples
observablerx-javafuturevert.x

Converting Vertx Future<T> To RX Observable<Optional<T>>


I need to provide some util function that converts a Vertx Future<T> to Rx Observable<Optional<T>> for backwards compatibility.

Should this be good enough?

Observable.fromCompletionStage(future.toCompletionStage());

Thanks


Solution

  • No, because Observable.fromCompletionStage returns Observable<T>, not Observable<Optional<T>>.

    You must create the Optional from the future result with ofNullable:

    Observable.fromCompletionStage(future.map(Optional::ofNullable).toCompletionStage());