Skip to content

Commit

Permalink
WASI: set the event loop on first DefaultExecutor access (#4240)
Browse files Browse the repository at this point in the history
Before, the event loop was only set when a non-delayed action
was being scheduled.

Fixes #4239
  • Loading branch information
dkhalanskyjb authored Oct 1, 2024
1 parent 58f880e commit 1c840d6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions kotlinx-coroutines-core/wasmWasi/src/EventLoop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ private fun sleep(nanos: Long, ptrTo32Bytes: Pointer, ptrTo8Bytes: Pointer, ptrT
}

internal actual object DefaultExecutor : EventLoopImplBase() {

init {
if (kotlin.wasm.internal.onExportedFunctionExit == null) {
kotlin.wasm.internal.onExportedFunctionExit = ::runEventLoop
}
}

override fun shutdown() {
// don't do anything: on WASI, the event loop is the default executor, we can't shut it down
}

override fun invokeOnTimeout(timeMillis: Long, block: Runnable, context: CoroutineContext): DisposableHandle =
scheduleInvokeOnTimeout(timeMillis, block)

actual override fun enqueue(task: Runnable) {
if (kotlin.wasm.internal.onExportedFunctionExit == null) {
kotlin.wasm.internal.onExportedFunctionExit = ::runEventLoop
}
super.enqueue(task)
}
}

internal actual abstract class EventLoopImplPlatform : EventLoop() {
Expand Down

0 comments on commit 1c840d6

Please sign in to comment.