title: How to wait for end of a coroutine
body: <p>I have some code below. Delay (3000) is just replacement for a long loop (or cycle). I’m expecting that after completion of loop <code>println(res)</code> will print “Some String” and then enable <code>button</code>. But in real life <code>println(res)</code> prints an empty string and <code>button</code> became enabled at same time when I click it. 
  My question is: how I can wait for end of a coroutine and only after completion of the coroutine  run <code>println(res)</code> and <code>button.isEnabled = true</code>.</p>
  
  <pre><code>private var res: String = ""
  
  private suspend fun test(): String {
      delay(3000) // delay - just replacement for long loop
      return "Some String" // String received after loop
  }
  
  fun onClick(view: View) {
      res = ""
      button.isEnabled = false
      GlobalScope.launch {
          res = withContext(Dispatchers.Default) {
              test()
          }
      }
      println(res) // 1. trying to get string received after loop, but not working
      button.isEnabled = true // 2. button must be enabled after loop in cycle, but it's not waiting till end of loop
  }
  </code></pre>