/** * Creates a ServiceFuture from an Completable object and a callback. * * @param completable the completable to create from * @param callback the callback to call when event happen * @return the created ServiceFuture */ public static ServiceFuture<Void> fromBody(final Completable completable, final ServiceCallback<Void> callback) { final ServiceFuture<Void> serviceFuture = new ServiceFuture<>(); completable.subscribe(new Action0() { Void value = null; @Override public void call() { if (callback != null) { callback.success(value); } serviceFuture.set(value); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { if (callback != null) { callback.failure(throwable); } serviceFuture.setException(throwable); } }); return serviceFuture; };
/** * Creates a ServiceCall from an observable object. * * @param observable the observable to create from * @param <T> the type of the response * @return the created ServiceCall */ public static <T> ServiceFuture<T> fromResponse(final Observable<ServiceResponse<T>> observable) { final ServiceFuture<T> serviceFuture = new ServiceFuture<>(); serviceFuture.subscription = observable .last() .subscribe(new Action1<ServiceResponse<T>>() { @Override public void call(ServiceResponse<T> t) { serviceFuture.set(t.body()); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { serviceFuture.setException(throwable); } }); return serviceFuture; }
final ServiceFuture<T> serviceFuture = new ServiceFuture<>(); serviceFuture.subscription = observable .last()
final ServiceFuture<T> serviceFuture = new ServiceFuture<>(); serviceFuture.subscription = observable .last()
final ServiceFuture<T> serviceFuture = new ServiceFuture<>(); serviceFuture.subscription = observable .last()