title: Retrofit: How to wait for response
body: <p>I have AsyncTask and the doInBackground method inside which, I sending POST request using Retrofit. My code looks like:</p>
  
  <pre><code>    //method of AsyncTask
      protected Boolean doInBackground(Void... params) {
          Retrofit restAdapter = new Retrofit.Builder()
                  .baseUrl(Constants.ROOT_API_URL)
                  .addConverterFactory(GsonConverterFactory.create())
                  .build();
          IConstructSecureAPI service = restAdapter.create(IConstructSecureAPI.class);
          //request
          Call&lt;JsonElement&gt; result = service.getToken("TestUser", "pass", "password");
          result.enqueue(new Callback&lt;JsonElement&gt;() {
              @Override
              public void onResponse(Call&lt;JsonElement&gt; call, Response&lt;JsonElement&gt; response) {
  
              }
  
              @Override
              public void onFailure(Call&lt;JsonElement&gt; call, Throwable t) {
  
              }
          });
  
          return true;
      }
  </code></pre>
  
  <p>The problem is: Retrofit sending request asynchronously and while it, the doInBackground method returning the value. So I need to send a request in the same thread with all executions in the sequence. One by one. And returning from doInBackground occurs after the request finished. How can I send a request in the same thread using Retrofit?</p>