@Test public void fromCompletableFuture() { final CompletableFuture<String> cf = CompletableFuture.supplyAsync(CompletableFutureToObservableTest::supplyValue); final Observable<String> observable = CompletableFutureToObservable.fromCompletableFuture(cf); observable.blockingSubscribe(System.out::println); System.out.println("Done"); }
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;} )); }
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;} )); } }
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;} )); }  }
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;} )); }  static Observable<T> fromCompletableFuture(CompletableFuture<T> cf); static Observable<T> fromCompletableFutureWhichShouldNotBeUsed(CompletableFuture<T> cf); }
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;} )); }  static Observable<T> fromCompletableFuture(CompletableFuture<T> cf); static Observable<T> fromCompletableFutureWhichShouldNotBeUsed(CompletableFuture<T> cf);  }