title: Kotlin Coroutines vs CompletableFuture
body: <p>Can anybody explain me why people should use coroutines? Is there some coroutine code example which shows better completion time against regular java concurrent code <em>(without magical delay() function, nobody uses <code>delay()</code> in production)</em> ?</p>
  
  <p>In my personal example coroutines(line 1) are suck against java code(line 2). Maybe i did something wrong?</p>
  
  <p>Example:</p>
  
  <pre><code>import kotlinx.coroutines.*
  import java.time.Instant
  import java.util.concurrent.CompletableFuture
  import java.util.concurrent.Future
  
  @ExperimentalCoroutinesApi
  fun main() = runBlocking {
      val begin = Instant.now().toEpochMilli()
      val jobs = List(150_000) {
          GlobalScope.launch { print(getText().await()) } // :1
  //        CompletableFuture.supplyAsync { "." }.thenAccept { print(it) } // :2
      }
      jobs.forEach { it.join() }
      println(Instant.now().toEpochMilli() - begin)
  }
  
  fun getText(): Future&lt;String&gt; {
      return CompletableFuture.supplyAsync {
          "."
      }
  }
  
  @ExperimentalCoroutinesApi
  suspend fun &lt;T&gt; Future&lt;T&gt;.await(): T = suspendCancellableCoroutine { cont -&gt;
      cont.resume(this.get()) {
          this.cancel(true)
      }
  }
  </code></pre>
  
  <p>Additional question: </p>
  
  <p>Why i should create this coroutine wrapper <code>await()</code>? It seems does not improve coroutine version of code otherwise <code>get()</code> method complains on <code>inappropriate blocking method call</code>?</p>