code: public void waitForPendingFutures() {
          // Wait inbox to become empty:
          Log.v(Log.TAG_BATCHER, "%s: waitForPendingFutures is called ...", this);
  
          while (true) {
              ScheduledFuture future;
              synchronized (mutex) {
                  while (!inbox.isEmpty()) {
                      try {
                          Log.v(Log.TAG_BATCHER, "%s: waitForPendingFutures, inbox size: %d",
                                  this, inbox.size());
                          mutex.wait(300);
                      } catch (InterruptedException e) {
                      }
                  }
                  future = pendingFuture;
              }
  
              // Wait till ongoing computation completes:
              if (future != null && !future.isDone() && !future.isCancelled()) {
                  try {
                      future.get();
                  } catch (Exception e) {
                      Log.e(Log.TAG_BATCHER, "%s: Error while waiting for pending futures", e, this);
                  }
              }
  
              synchronized (mutex) {
                  if (inbox.isEmpty())
                      break;
              }
          }
  
          Log.v(Log.TAG_BATCHER, "%s: waitForPendingFutures done", this);
      }
docs: Wait for the **current** items in the queue to be all processed.
  
  Note: Calling this method on the same thread as the WorkExecutor set to the batcher
  will result to deadlock.