0

I want to send multiple API requests, so I'm using RxJava's Zip operator, I want to know the success rate of the API requests to show it to the user, but here, whenever one request getting failed, I couldn't see any logs inside the complete method,

How to listen over all the responses together (success/fail) and find the success rate?

    List<io.reactivex.rxjava3.core.Observable<Object>> requests = new ArrayList<>();
requests.add(
    RetrofitInstance.getRetrofitClient()
        .create(IService.class)
        .sendMessage("123", com)); // my custom model class

Observable
    .zip(requests, // list of API requests
        new Function<Object[], List<Object>>() {
          @Override
          public List<Object> apply(Object[] objects) throws Exception {
            Log.d("onSubscribe", "apply: " + objects.length);

            for (Object o : objects) {
              Log.d(TAG, "apply: %%%%% " + o.toString());
              messageResponse.add((Object) o);
            }

            if (messageResponse.size() == requests.size()) {
              Log.d(TAG, "apply: req size " + requests.size());
            }
            Log.d(TAG, "apply: @@4");
            msgResponse[0] = true;
            return messageResponse;
          }
        })
    .subscribeOn(Schedulers.io())
    .subscribe(new Observer<List<Object>>() {
      @Override
      public void onSubscribe(
          @io.reactivex.rxjava3.annotations.NonNull Disposable d) {
        Log.d(TAG, "onSubscribe: ");
      }

      @Override
      public void onNext(
          @io.reactivex.rxjava3.annotations.NonNull List<Object> objects) {
        Log.d(TAG, "onNext: ");
      }

      @Override
      public void onError(
          @io.reactivex.rxjava3.annotations.NonNull Throwable e) {
        Log.d(TAG, "onError: ");
      }

      @Override
      public void onComplete() {
        Log.d(TAG, "onComplete: ");
      }
    });
FGH
  • 2,900
  • 6
  • 26
  • 59
  • Please [edit] your question to include your source code as a working [mcve], which can be compiled and tested by others. – Progman Nov 05 '22 at 13:21
  • Why are you reposting the same question? I already suggested you materialize your sources to the zip so you have success and failed notifications to work with in zip. – akarnokd Nov 06 '22 at 18:40

0 Answers0