Overview
Summaryβ
Kotlin compiler plugin for generating platform-compatible functions for suspend functions.
Quick Exampleβ
JVM Platformβ
class Foo {
@JvmBlocking
@JvmAsync
@JvmReactive
suspend fun waitAndGet(): String {
delay(5)
return "Hello"
}
}
The plugin automatically generates:
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() }
@Api4J
fun waitAndGetReactive(): Publisher<String> = runInReactive { waitAndGet() }
}
@JvmReactive returns a Reactive Streams Publisher and completes empty when
the suspend function returns null.
Enable addJvmReactive() explicitly and add the required reactive dependencies
to the user JVM classpath manually. See
Default Transformers.
JavaScript Platformβ
class Foo {
@JsPromise
suspend fun waitAndGet(): String {
delay(5)
return "Hello"
}
}
The plugin automatically generates:
class Foo {
suspend fun waitAndGet(): String {
delay(5)
return "Hello"
}
@Api4Js
fun waitAndGetAsync(): Promise<String> = runInAsync { waitAndGet() }
}
Platform Support Statusβ
| Platform | Since Version |
|---|---|
| JVM | 0.1.0 |
| JavaScript | 0.6.0 |
| WasmJS (Experimental) | 0.6.0 |