Skip to main content
Version: v2.2.0-0.13.1

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
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() }
}

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.