title: Returning a value produced in Kotlin coroutine
body: <p>I am trying to return a value generated from coroutine</p>
  
  <pre><code>fun nonSuspending (): MyType {
      launch(CommonPool) {
          suspendingFunctionThatReturnsMyValue()
      }
      //Do something to get the value out of coroutine context
      return somehowGetMyValue
  }
  </code></pre>
  
  <p>I have come up with the following solution (not very safe!):</p>
  
  <pre><code>fun nonSuspending (): MyType {
      val deferred = async(CommonPool) {
          suspendingFunctionThatReturnsMyValue()
      }
      while (deferred.isActive) Thread.sleep(1)
      return deferred.getCompleted()
  }
  </code></pre>
  
  <p>I also thought about using event bus, but is there a more elegant solution to this problem?</p>
  
  <p>Thanks in advance.</p>