suspend
Начиная с Kotlin: 1.2
inline fun <R> suspend(noinline block: suspend () -> R): suspend () -> R
Построитель функционального типа, который гарантирует, что заданный блок имеет модификатор suspend и может использоваться как suspend-функция.
По умолчанию объявления функциональных типов не выводятся как suspend и не могут использоваться таким образом:
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
© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/suspend.html