title: Parallel request with Retrofit, Coroutines and Suspend functions
body: <p>I'm using Retrofit in order to make some network requests. I'm also using the Coroutines in combination with 'suspend' functions.</p>
  
  <p>My question is: Is there a way to improve the following code. The idea is to launch multiple requests in parallels and wait for them all to finish before continuing the function.</p>
  
  <pre><code>lifecycleScope.launch {
      try {
          itemIds.forEach { itemId -&gt;
              withContext(Dispatchers.IO) { itemById[itemId] = MyService.getItem(itemId) }
          }
      } catch (exception: Exception) {
          exception.printStackTrace()
      }
  
      Log.i(TAG, "All requests have been executed")
  }
  </code></pre>
  
  <p>(Note that "MyService.getItem()" is a 'suspend' function.)</p>
  
  <p>I guess that there is something nicer than a <em>foreach</em> in this case.</p>
  
  <p>Anyone with an idea?</p>