From 5ea018c072fccc52bd3155300b3d2b552619d612 Mon Sep 17 00:00:00 2001 From: Dmitry Khalanskiy <52952525+dkhalanskyjb@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:59:12 +0200 Subject: [PATCH] Set the event loop whenever DefaultExecutor is accessed Before, the event loop was only set when a non-delayed action was being scheduled. Fixes #4239 --- kotlinx-coroutines-core/wasmWasi/src/EventLoop.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kotlinx-coroutines-core/wasmWasi/src/EventLoop.kt b/kotlinx-coroutines-core/wasmWasi/src/EventLoop.kt index aac143d022..a0f392e5b0 100644 --- a/kotlinx-coroutines-core/wasmWasi/src/EventLoop.kt +++ b/kotlinx-coroutines-core/wasmWasi/src/EventLoop.kt @@ -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() {