Skip to content

Instantly share code, notes, and snippets.

@GauravChaddha1996
Created January 30, 2021 18:14
Show Gist options
  • Save GauravChaddha1996/a6394e141d2f2b608614bdf2c5ae98f6 to your computer and use it in GitHub Desktop.
Save GauravChaddha1996/a6394e141d2f2b608614bdf2c5ae98f6 to your computer and use it in GitHub Desktop.
fun taskT(): Job {
return GlobalScope.launch(Dispatchers.IO) {
println("Starting C on ${Thread.currentThread().name}\n")
/*
* Next we need to do task 'T1' which is a network call. So we call t1()
*
* suspension: Since t1() is marked suspend, it'll suspend
* the calling function. But since the code of 't1' isn't
* launching a new coroutine, the same coroutine will be
* used to execute t1(). Meaning we continue as if it's
* just a synchronous function and the calling function
* isn't executing any further i.e. only when t1 returns
* with the result will T execute any further.
* Task name: T1
* Coroutine name: C1 which is just C
* Thread pool: Still IO as we are on 'C'
*
* We make the network call and then return the result.
* */
val resultT1 = t1()
// Further code omitted
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment