title: Coroutines: runBlocking vs coroutineScope
body: <p>I was reading <a href="https://kotlinlang.org/docs/reference/coroutines/basics.html" rel="noreferrer">Coroutine Basics</a> trying to understand and learn it.</p>
  
  <p>There is a part there with this code:</p>
  
  <pre><code>fun main() = runBlocking { // this: CoroutineScope
      launch { 
          delay(200L)
          println("Task from runBlocking")
      }
  
      coroutineScope { // Creates a new coroutine scope
          launch {
              delay(900L) 
              println("Task from nested launch")
          }
  
          delay(100L)
          println("Task from coroutine scope") // This line will be printed before nested launch
      }
  
      println("Coroutine scope is over") // This line is not printed until nested launch completes
  }
  </code></pre>
  
  <p>The output goes like so:</p>
  
  <pre><code>Task from coroutine scope
  Task from runBlocking
  Task from nested launch
  Coroutine scope is over
  </code></pre>
  
  <p>My question is why this line:</p>
  
  <pre><code> println("Coroutine scope is over") // This line is not printed until nested launch completes
  </code></pre>
  
  <p>is called always last?</p>
  
  <p>Shouldn't it be called since the:</p>
  
  <pre><code>coroutineScope { // Creates a new coroutine scope
      ....
  }
  </code></pre>
  
  <p>is suspended?</p>
  
  <p>There is also a note there:</p>
  
  <blockquote>
    <p>The main difference between runBlocking and coroutineScope is that the latter does not block the current thread while waiting for all children to complete.</p>
  </blockquote>
  
  <p>I dont understand how coroutineScope and runBlocking are different here? coroutineScope looks like its blocking since it only gets to the last line when it is done.</p>
  
  <p>Can anyone enlighten me here?</p>
  
  <p>Thanks in advance.</p>