reactive programming - RXJava Android - Observable result needed to create another observable -


i cant find way combine or chain list of observables it´s responses prerequisites other call creates observable.

i´m using retrofit observables.

my service:

string url = "/geocode/json?sensor=false";  @get(url) observable<geocoderesult> getreverse(@query("key") string gmapskey,                                      @query("latlng") latlng origin); 

and service needs geocoderesult

@post("/api/orders") observable<order> createorder(@body geocoderesult neworder); 
  1. and i´m trying with:

    // prerequisite 1 observable geocodeobservable = address.get(...);

    // call createorder after geocode obtained? return observable.combinelatest(geocodeobservable, geocode -> createorder(geocode));

but don´t work because combinelatest needs object, not observable need return observable.

with joinobservable:

pattern5<geocode> pattern = joinobservable.from(geocodeobservable) plan0<observable<order>> plan = pattern.then(order::create); return joinobservable.when(plan).toobservable().toblocking().single(); 

but throws nosuchelementexception exception. why?

i toblocking().single() because need observable , not observable<observable<order>> :(.

or how can it?

you try using flatmap can take second observable parameter.

the function takes items emitted first observable , creates observable each of items , flattens items emitted observables single observable. sounds complex, fortunately both retrofit functions emit single item, 1 observable gets "flattened" observable.

you can use flatmap this:

restapi.getreverse(gmapskey, origin)     .flatmap(geocoderesult -> createorder(geocoderesult))     .subscribe(order -> dosomething(order)); 

combinelatest doesn't fit needs, because perform both rest calls @ same time, not 1 after other, can't use response of first 1 parameter of second. can't comment on why exception gets thrown joinobservable because it's not part of public api. toblocking() shouldn't used other testing.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -