title: How to run Kotlin coroutines sequentially?
body: <p>I have an instance of <code>CoroutineScope</code> and <code>log()</code> function which look like the following:</p>
  <pre><code>private val scope = CoroutineScope(Dispatchers.IO)
  
  fun log(message: String) = scope.launch { // launching a coroutine
      println(&quot;$message&quot;)
      TimeUnit.MILLISECONDS.sleep(100) // some blocking operation
  }
  </code></pre>
  <p>And I use this test code to launch coroutines:</p>
  <pre><code>repeat(5) { item -&gt;
      log(&quot;Log $item&quot;)
  }
  </code></pre>
  <p>The <code>log()</code> function can be called from any place, in any <code>Thread</code>, but not from a coroutine.</p>
  <p>After a couple of tests I can see not sequential result like the following:</p>
  <pre><code>Log 0
  Log 2
  Log 4
  Log 1
  Log 3
  </code></pre>
  <p>There can be different order of printed logs. If I understand correctly the execution of coroutines doesn't guarantee to be sequential. What it means is that a coroutine for <code>item 2</code> can be launched before the coroutine for <code>item 0</code>.</p>
  <p>I want that coroutines were launched sequentially for each item and &quot;some blocking operation&quot; would execute sequentially, to always achieve next logs:</p>
  <pre><code>Log 0
  Log 1
  Log 2
  Log 3
  Log 4
  </code></pre>
  <p>Is there a way to make launching coroutines sequential? Or maybe there are other ways to achieve what I want?</p>
  <p>Thanks in advance for any help!</p>