Skip to content Skip to sidebar Skip to footer

Calling Four Api's Combining Together Using RxJava

I am new to RxJava Restapi.class /************/ @GET('app/dashboard') Observable getCategories(@HeaderMap Map headers);

Solution 1:

using this way

List<Observable<?>> observables = Lists.newArrayList(categoriesObservable, walletObservable, settingsObservable, ratingsObservable);
            Observable.merge(observables).toList().subscribe(new Action1<List<Object>>() {
                @Override
                public void call(List<Object> objects) {
                    // success
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    // error
                }
            });

or you can using mergeDelayError instead

hope this helps


Solution 2:

You can use Zip operator

Observable<String> result = 
Observable.zip(categoriesObservable, walletObservable, settingsObservable, ratingsObservable, new Function4<CategoryHomeModel, WalletBalance, Settings, SwapSettings, String>() {
    @Override
    public String apply(CategoryHomeModel category, WalletBalance wallet, Settings settings, SwapSettings swap) {
        String res = category.name + wallet.name + settings.name + swap.name;
        // You can customize the final result based upon your requirements
        return res;
    }
});

Post a Comment for "Calling Four Api's Combining Together Using RxJava"