新版本的变更 / Kotlin 1.6

import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking

// *** before: ***
// class OldTask : suspend () -> Unit   // <- Error: not allowed as a supertype

class OldTask {
    suspend fun run() {                 // a class with a method, plus a wrapper
        delay(10)
    }
}

// *** in version 1.6: ***
class Task(val name: String) : suspend () -> Unit {
    override suspend fun invoke() {
        delay(10)
        println("done: $name")
    }
}

suspend fun launchAll(tasks: List<suspend () -> Unit>) {
    for (t in tasks) t()
}

fun main() = runBlocking {
    launchAll(listOf(Task("first"), Task("second")))
}