title: How to run several Kotlin coroutines in parallel and wait for them to complete before proceeding
body: <p>I need to run 2 coroutines in parallel and wait for them to finish before proceeding. The code below works but it uses <code>GlobalScope</code> which is not the best way to do it.</p>
  
  <p>Is there a better way?</p>
  
  <pre><code>fun getInfo(onSuccess: () -&gt; Unit, onError: () -&gt; Unit) {
          GlobalScope.launch(Dispatchers.IO) {
              try {
                  coroutineScope {
                      launch { getOne() }
                      launch { getTwo() }
                  }
                  onSuccess.invoke()
              } catch (e: Throwable) {
                  onError.invoke()
              }
          }
      }
  </code></pre>