Suspending functions

Coroutines in Kotlin include the notion of suspending functions. Suspending functions are denoted by adding the suspend modifier to a function definition. There are two key things to remember regarding suspending functions:

If we return to our working example, we can see an example of the suspend function, delay():

fun main() {
GlobalScope.launch {
delay(500) // simulate network request
println("Coroutines")
}
println("Hello")
Thread.sleep(1000)
}

delay() is a suspending function that will suspend the current coroutine for a specified amount of time. Suspending functions is the primary mechanism by means of which we can suspend our current coroutine, go and do some other work, and then resume the coroutine once that work is finished.