Kotlin 挂起函数转换编译器插件
 
概述
用于为挂起函数生成平台兼容函数的 Kotlin 编译器插件。
快速示例
JVM 平台
class Foo {
    @JvmBlocking
    @JvmAsync
    suspend fun waitAndGet(): String {
        delay(5)
        return "Hello"
    }
}
插件会自动生成:
class Foo {
    @JvmSynthetic
    suspend fun waitAndGet(): String {
        delay(5)
        return "Hello"
    }
    @Api4J
    fun waitAndGetBlocking(): String = runInBlocking { waitAndGet() }
    @Api4J
    fun waitAndGetAsync(): CompletableFuture<out String> = runInAsync { waitAndGet() }
}
JavaScript 平台
class Foo {
    @JsPromise
    suspend fun waitAndGet(): String {
        delay(5)
        return "Hello"
    }
}
插件会自动生成:
class Foo {
    suspend fun waitAndGet(): String {
        delay(5)
        return "Hello"
    }
    @Api4Js
    fun waitAndGetAsync(): Promise<String> = runInAsync { waitAndGet() }
}
平台支持状态
| 平台 | 起始版本 | 
|---|---|
| JVM | 0.1.0 | 
| JavaScript | 0.6.0 | 
| WasmJS (实验性) | 0.6.0 |