suspend

inline fun <R> suspend(noinline block: suspend () -> R): suspend () -> R(source)

A functional type builder that ensures the given block has a suspend modifier and can be used as a suspend function.

By default, functional type declarations are not inferred as suspend and cannot be used as such:

suspend fun yield() {}

// Inferred type: '() -> Unit'
val regularBlock = { yield() } // Does not compile, `yield` requires to be in the suspend context
// Inferred type: 'suspend () -> Unit'
val suspendBlock = suspend { yield() } // Compiles as expected

Since Kotlin

1.2