title: What does the suspend function mean in a Kotlin Coroutine?
body: <p>I'm reading Kotlin Coroutine and know that it is based on <code>suspend</code> function. But what does <code>suspend</code> mean?</p>
  <p><strong>Coroutine or function gets suspended?</strong></p>
  <p>From <a href="https://kotlinlang.org/docs/reference/coroutines.html" rel="noreferrer">https://kotlinlang.org/docs/reference/coroutines.html</a></p>
  <blockquote>
  <p>Basically, coroutines are computations that can be suspended without blocking a thread</p>
  </blockquote>
  <p>I heard people often say &quot;suspend function&quot;. But I think it is the coroutine who gets suspended because it is waiting for the function to finished? &quot;suspend&quot; usually means &quot;cease operation&quot;, in this case the coroutine is idle.</p>
  <p>Should we say the coroutine is suspended ?</p>
  <p><strong>Which coroutine gets suspended?</strong></p>
  <p>From <a href="https://kotlinlang.org/docs/reference/coroutines.html" rel="noreferrer">https://kotlinlang.org/docs/reference/coroutines.html</a></p>
  <blockquote>
  <p>To continue the analogy, await() can be a suspending function (hence also callable from within an async {} block) that suspends a coroutine until some computation is done and returns its result:</p>
  </blockquote>
  <pre><code>async { // Here I call it the outer async coroutine
      ...
      // Here I call computation the inner coroutine
      val result = computation.await()
      ...
  }
  </code></pre>
  <p>It says &quot;that suspends a coroutine until some computation is done&quot;, but coroutine is like a lightweight thread. So if the coroutine is suspended, how can the computation is done ?</p>
  <p>We see <code>await</code> is called on <code>computation</code>, so it might be <code>async</code> that returns <code>Deferred</code>, which means it can start another coroutine</p>
  <pre><code>fun computation(): Deferred&lt;Boolean&gt; {
      return async {
          true
      }
  }
  </code></pre>
  <p>The quote say <em><strong>that suspends a coroutine</strong></em>. Does it mean <code>suspend</code> the outer <code>async</code> coroutine, or <code>suspend</code> the inner <code>computation</code> coroutine?</p>
  <p>Does <code>suspend</code> mean that while outer <code>async</code> coroutine is waiting (<code>await</code>) for the inner <code>computation</code> coroutine to finish, it (the outer <code>async</code> coroutine) idles (hence the name suspend) and returns thread to the thread pool, and when the child <code>computation</code> coroutine finishes, it (the outer <code>async</code> coroutine) wakes up, takes another thread from the pool and continues?</p>
  <p>The reason I mention the thread is because of <a href="https://kotlinlang.org/docs/tutorials/coroutines-basic-jvm.html" rel="noreferrer">https://kotlinlang.org/docs/tutorials/coroutines-basic-jvm.html</a></p>
  <blockquote>
  <p>The thread is returned to the pool while the coroutine is waiting, and when the waiting is done, the coroutine resumes on a free thread in the pool</p>
  </blockquote>