title: Kotlin Coroutines sequential execution
body: <p>I'm trying to create an object which can execute some tasks sequentially in its own thread like it is a queue. </p>
  
  <p>The following sample is just for demonstrating my setup and may be completely wrong.</p>
  
  <pre><code>class CoroutinesTest {
      fun a() {
          GlobalScope.launch {
              println("a started")
              delay(1000)
              println("a completed")
          }
      }
  
      fun b() {
          GlobalScope.launch {
              println("b started")
              delay(2000)
              println("b completed")
          }
      }
  
      fun complex() {
          a()
          b()
      }
  }
  
  fun main() {
      runBlocking {
          val coroutinesTest = CoroutinesTest()
  
          coroutinesTest.complex()
  
          delay(10000)
      }
  }
  </code></pre>
  
  <p>For now this code prints the following</p>
  
  <pre><code>a started
  b started
  a completed
  b completed
  </code></pre>
  
  <p>which means <code>a</code> and <code>b</code> executed in parallel. Methods <code>a</code>, <code>b</code> and <code>complex</code> can be called from different threads. Of course, the <code>complex</code> method should also support this concept. For now, I need a mechanism that allows me to execute only one task at a moment, so I could get the following output:</p>
  
  <pre><code>a started
  a completed
  b started
  b completed
  </code></pre>
  
  <p>I did some research and think that <code>actor</code> with a <code>Channel</code> can do what needed, but <code>actor</code> for now is marked as <em>obsolete</em> (<a href="https://github.com/Kotlin/kotlinx.coroutines/issues/87" rel="noreferrer">issue #87</a>). I don't like the idea of using API that is subject to change, so I would like to do the thing in a common way.</p>