Kotlin Coroutines in a Android Service : <p>I have a android service which starts and syncs different types of data with the server when it's online.
I'm new to Kotlin coroutines and I'm trying to accomplish the following:</p>

<pre><code>fun syncData{
//Job1 make retrofit call to server
//Job2 make retrofit call to server after job1 is done.
//Job3 make retrofit call to server after job 2 is done and so on. 
//After all jobs are done I'll stop service.
}
</code></pre>

<p>I'm following this post: 
<a href="https://stackoverflow.com/questions/43132080/kotlin-coroutines-the-right-way-in-android">Kotlin Coroutines the right way in Android</a></p>

<p>Which brought me this solution:</p>

<pre><code>fun syncData() = async(CommonPool){
    try{

        val sync1 = async(CommonPool){
            job1.sync()
        }

        val sync2 = async(CommonPool){
            job2.sync()
        }


        val sync3 = async(CommonPool){
            job3.sync()
        }

        val sync4 = async(CommonPool){
            job4.sync()
        }
        job1.await()
        job2.await()
        job3.await()
        job4.await()
    }catch (e: Exception){
    }finally {
        stopSelf()
    }
}
</code></pre>

<p>But when I get retrofit's log on logcat every call is mixed. Calls from job3 comes before job1, and so on.
How can I execute then in a pipeline ?I'm kinda lost in kotlin's coroutines so I don't know exactly to implement this.</p>

<p>Thanks in advance.</p>
