https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

aeruhxi

03/04/2020, 9:15 AM
Copy code
/**
 * You can edit, run, and share this code. 
 * <http://play.kotlinlang.org|play.kotlinlang.org> 
 */

import kotlinx.coroutines.*

fun main() {
    println("Hello, world!!!")
    CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>).launch {
        (1..1000).forEach {
            suspend {
                delay(2000)
                print("Testing...")
            }
        }
    }
}
What kind of block is
suspend {}
?
e

elizarov

03/04/2020, 9:27 AM
It is a suspending lamba. Just like
{}
block, but the code can suspend inside. Assign to a variable to use it, like this:
val block = suspend { … }
.
👍 1
a

aeruhxi

03/08/2020, 5:49 AM
Got it. Thanks.