When a suspend function calls another, is there an...
# getting-started
a
When a suspend function calls another, is there an assurance of the order of operations and whether they are synchronous or not? Will this always print A-B-C regardless of under which conditions x is invoked?
Copy code
suspend fun x() {
  print("A")
  y()
  print("C")
}
suspend fun y() {
  print("B")
}
e
unless a
suspend fun
escapes structured concurrency (either by explicitly giving it a
CoroutineScope
to allow it to do so, or if it breaks conventions by launching into an unrelated scope) then all `suspend fun`s run to completion in sequence
in short: your code will not print A-C-B out of order
this might print A-B-C or A-C-B:
Copy code
suspend fun x() {
    coroutineScope {
        print("A")
        y(this@coroutineScope)
        print("B")
    }
}
fun y(scope: CoroutineScope) {
    scope.launch {
        print("C")
    }
}
a
thank you so much for your answers
@ephemient++
p
|Will this always print A-B-C regardless... You mean 'A-C-B' in your question right?
e
oh lol, that affected my responses too
a
yeah sorry meant ACB lol
but i think we all understood the idea hahah
edited
p
😁