rx java2 - RxJava Single.concat -
i have following code:
model.getcategories() .subscribeon(schedulers.io()) .observeon(androidschedulers.mainthread()) .subscribe(new action1<list<category>>() { @override public void call(final list<category> categories) { model.getunits() .subscribeon(schedulers.io()) .observeon(androidschedulers.mainthread()) .subscribe(new action1<list<unit>>() { @override public void call(list<unit> units) { view.showaddproductdialog(units, categories); } }); } }); i have ugly nesting. how can fix it. tried this:
single.concat(model.getcategories(), model.getunits()) .subscribeon(schedulers.io()) .observeon(androidschedulers.mainthread()) .subscribe(new action1<list<? extends object>>() { @override public void call(list<? extends object> objects) { // } }); but problem cannot determinate whether list<category> or list<unit> comes.
is there way use concat , detect kind of stream comes (list<category> or list<unit> or else) ?
also need detect observers completed perform action.
thanks in advice.
use single.zip():
single.zip( getcategories().subscribeon(schedulers.io()), getunits().subscribeon(schedulers.io()), (a, b) -> pair.of(a, b) ) .observeon(androidschedulers.mainthread()) .subscribe( pair -> view.showaddproductdialog(pair.first, pair.second), error -> showerror(error.tostring()) ) where pair can tuple implementation, i.e., this.
Comments
Post a Comment