title: How to wait for callback with Retrofit, RxJava
body: <p>I am making multiple Retrofit requests and with every request I need to generate new client with new token. The problem is it is not waiting for it to finish so the client is <code>null</code>. I tried to add callback to <code>generatePrivateToken()</code> as well but it did not work.</p>
  
  <pre><code>public void generatePrivateToken(){
          mNewControl.obstest(GETTOKEN)
                  .subscribeOn(Schedulers.io())
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribe(new Observer&lt;Response&lt;ResponseBody&gt;&gt;() {
                      @Override
                      public void onSubscribe(Disposable d) {
                      }
                      @Override
                      public void onNext(Response&lt;ResponseBody&gt; responseBodyResponse) {
                          key = responseBodyResponse.headers().get("Token");
                          new ApiKeys().encryptToken(key, new GeneralCallback() {
                              @Override
                              public void onSuccess(String token) {
                                  Log.e("Token", token);
                                  client = new HttpClient(USERNAME,token, emptyTag, emptyTag).getClient();
                              }
                          });
                      }
                      @Override
                      public void onError(Throwable e) {
                      }
                      @Override
                      public void onComplete() {
  
                      }
                  });
      }
  
  public void getControlData(){
      generatePrivateToken();
  
      Retrofit retrofit = new Retrofit.Builder()
              .baseUrl(HOST_URL)
              .client(client)
              .addConverterFactory(GsonConverterFactory.create())
              .build();
      newControl service = retrofit.create(newControl.class);
      Call&lt;List&lt;GetControlData&gt;&gt; call = service.controlData(CONTROL);
      call.enqueue(new Callback&lt;List&lt;GetControlData&gt;&gt;() {
          @Override
          public void onResponse(Call&lt;List&lt;GetControlData&gt;&gt; call, Response&lt;List&lt;GetControlData&gt;&gt; response) {
              //do something, start new retrofit method
          }
          @Override
          public void onFailure(Call&lt;List&lt;GetControlData&gt;&gt; call, Throwable t) {
          }
      });
  
  }
  </code></pre>