class CompletableFutureToObservable {

    public static <T>Observable<T> fromCompletableFuture(CompletableFuture<T> cf) {
        return Observable.create(subscriber -> cf.thenAccept(value -> { subscriber.onNext(value); subscriber.onComplete(); })
                .exceptionally(ex -> { subscriber.onError(ex); return null;} ));
    }

}

class CompletableFutureToObservableTest {

    @Test
    public void fromCompletableFuture() {

        final CompletableFuture<String> cf = CompletableFuture.supplyAsync(CompletableFutureToObservableTest::supplyValue);

        //final Observable<String> observable = CompletableFutureToObservable.fromCompletableFuture(cf);
        final Observable<String> observable = CompletableFutureToObservable.fromCompletableFuture(cf);

        observable.blockingSubscribe(System.out::println);


        System.out.println("Done");

    }

}