Skip to main content
Version: v2.4.0-0.14.0

Overview

Maven Central Gradle Plugin Portal

cover

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​

PlatformSince Version
JVM0.1.0
JavaScript0.6.0
WasmJS (Experimental)0.6.0
note

JS platform support was added in version 0.6.0. See the implementation details at KT-53993 and PR #39.