title: Repository method sets LiveData value inside Asynchronous Retrofit call
body: <p>When going through the official guide for the Android <a href="https://developer.android.com/topic/libraries/architecture/guide" rel="noreferrer">Architecture Components</a>, in the section that explains the repository layer with a Retrofit request there is a piece of code I cannot seem to fully understand:</p>
  
  <pre><code>public class UserRepository {
      private Webservice webservice;
      // ...
      public LiveData&lt;User&gt; getUser(int userId) {
          // This is not an optimal implementation, we'll fix it below
          final MutableLiveData&lt;User&gt; data = new MutableLiveData&lt;&gt;();
          webservice.getUser(userId).enqueue(new Callback&lt;User&gt;() {
              @Override
              public void onResponse(Call&lt;User&gt; call, Response&lt;User&gt; response) {
                  // error case is left out for brevity
                  data.setValue(response.body());
              }
          });
          return data;
      }
  }
  </code></pre>
  
  <p>At this stage we are initializing our <code>LiveData</code> object:</p>
  
  <pre><code>final MutableLiveData&lt;User&gt; data = new MutableLiveData&lt;&gt;();
  </code></pre>
  
  <p>Then in the retrofit asynchronous call, we set the value for that variable.</p>
  
  <p>As this is an asynchronous call, wouldn't that method just return the data initialized but never with the value set?</p>