Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxJava - Start one Observable when other one finish

I have two Observables with different generic types: Observable o1 and Observable o2

I was defined to o1 the onComplet() and onNext() functions and i want that when this Observable get their finish then the o2 can start.

I tryed the Observable.concat() but they have different types, so this approach doesn't work...

So How can i do this?

like image 550
pablobaldez Avatar asked Jul 30 '15 19:07

pablobaldez


1 Answers

Use castAs before concatWith (and ignoreElements can be useful too):

Observable<T> o1;
Observable<R> o2;

Observable<R> o3 = 
  o1.ignoreElements()
    .castAs(R.class)
    .concatWith(o2);

Or if you're working with generic types (thus can't use R.class):

Observable<R> o3 = ((Observable<R>)(Observable<?>)
  o1.ignoreElements())
    .concatWith(o2);
like image 88
Dave Moten Avatar answered Sep 19 '22 20:09

Dave Moten