title: How to wait for the server response when multiple requests occur with RX Java & Retrofit?
body: <p>I'm doing multiple POSTs requests and I would like wait until the server comes back with a response after each POST. </p>
  
  <p>Here is my code from the presenter:</p>
  
  <pre><code>    public void sendMessage(final Message message, final String mediaFileName) {
  
      messageSender.sendMessage(message)
              .subscribeOn(processScheduler)
              .subscribe(new DisposableSubscriber&lt;Response&lt;ResponseBody&gt;&gt;() {
                  @Override
                  public void onNext(Response&lt;ResponseBody&gt; responseBodyResponse) {
                      if (responseBodyResponse.code() &gt;= 200 &amp;&amp; responseBodyResponse.code() &lt; 300 &amp;&amp; responseBodyResponse.isSuccessful()) {
                          SharedPrefs.setLastMessageId(message.getMsgId());
                          Timber.d("Sent message: " + message.getContent() + " with id " + message.getMsgId());
                      }
                  }
  
                  @Override
                  public void onError(Throwable t) {
                      Timber.e("Error occurred while attempting to send message: " + t.getMessage());
                  }
  
                  @Override
                  public void onComplete() {
                      if (mediaFileName != null) {
                          retrieveMediaFile(mediaFileName, message);
  
                      }
                  }
              });
  
  }
  </code></pre>
  
  <p>Here is the interactor :</p>
  
  <pre><code>public class MessageSenderImpl implements MessageSender {
  
  private final Service service;
  private final AuthCredentials authCredentials;
  
  public MessageSenderImpl(Service service, AuthCredentials authCredentials) {
      this.service = service;
      this.authCredentials = authCredentials;
  }
  
  @Override
  public Flowable&lt;Response&lt;ResponseBody&gt;&gt; sendMessage(Message message) {
      return service.sendMessage(authCredentials.auth(), message);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and my request:</p>
  
  <pre><code>@POST("someEndPoint")
  Flowable&lt;Response&lt;ResponseBody&gt;&gt; sendMessage(@Header("Authorization") String auth, @Body Message message);
  </code></pre>
  
  <p>If for example I'm sending 10 POSTs, the response from the 3rd request might come back after the 10th one.</p>
  
  <p>Note: Newbie in the RX world.
  Thank you in advance!</p>