<@U2E974ELT> So basically this is how I would do ...
# coroutines
j
@elizarov So basically this is how I would do it;
Copy code
kotlin
suspend fun countdown() {
    for (i in 1..10) {
        await(delay(1000))
        print("T-Minus $i")
    }
}

fun main(args: Array<String>) {
    run {
        await(countdown())
    }
}
Anything marked with
suspend
can be awaited. await will simply wait until the completion of what was marked and then return anything that was returned.
Copy code
kotlin
suspend fun countdown() {
    while (true) {
        yield()
    }
}

fun main(args: Array<String>) {
    run {
        spawn(countdown())
        spawn(countdown()).join()
    }
}
yield
explicitly gives up control.
spawn
takes a
suspend
and creates a
Job|Task
from it. These tasks are joinable and run concurrently with other tasks and can be canceled.