Kotlin / kotlinx.coroutines

Library support for Kotlin coroutines
Apache License 2.0
13.1k stars 1.86k forks source link

Wasm/WASI: calling delay() silently exits wasmWasiNodeRun #4239

Open OliverO2 opened 2 months ago

OliverO2 commented 2 months ago

Versions:

Running the following code in commonMain:

import kotlinx.coroutines.delay
import kotlin.time.Duration.Companion.seconds

suspend fun main() {
    println("main: before delay")
    delay(1.seconds)
    println("main: after delay")
}

This works on Wasm/JS,

> Task :wasmJsNodeRun
main: before delay
main: after delay

but silently exits on Wasm/WASI:

> Task :wasmWasiNodeRun
main: before delay
dkhalanskyjb commented 2 months ago

Workaround:

import kotlinx.coroutines.delay
import kotlin.time.Duration.Companion.seconds

suspend fun main() {
    withContext(Dispatchers.Default) { }
    println("main: before delay")
    delay(1.seconds)
    println("main: after delay")
}