diff --git a/src/dorkbox/network/connection/ListenerManager.kt b/src/dorkbox/network/connection/ListenerManager.kt index f0b7b870..a11ec9a2 100644 --- a/src/dorkbox/network/connection/ListenerManager.kt +++ b/src/dorkbox/network/connection/ListenerManager.kt @@ -21,7 +21,6 @@ import dorkbox.os.OS import dorkbox.util.classes.ClassHelper import dorkbox.util.classes.ClassHierarchy import kotlinx.atomicfu.atomic -import kotlinx.coroutines.runBlocking import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import mu.KLogger @@ -371,16 +370,14 @@ internal class ListenerManager(private val logger: KLogg /** * Invoked when a connection is first initialized, but BEFORE it's connected to the remote address. */ - fun notifyInit(connection: CONNECTION) { - runBlocking { - onInitList.value.forEach { - try { - it(connection) - } catch (t: Throwable) { - // NOTE: when we remove stuff, we ONLY want to remove the "tail" of the stacktrace, not ALL parts of the stacktrace - cleanStackTrace(t) - logger.error("Connection ${connection.id} error", t) - } + suspend fun notifyInit(connection: CONNECTION) { + onInitList.value.forEach { + try { + it(connection) + } catch (t: Throwable) { + // NOTE: when we remove stuff, we ONLY want to remove the "tail" of the stacktrace, not ALL parts of the stacktrace + cleanStackTrace(t) + logger.error("Connection ${connection.id} error", t) } } } diff --git a/src/dorkbox/network/handshake/ServerHandshake.kt b/src/dorkbox/network/handshake/ServerHandshake.kt index f77b5a55..b03ab547 100644 --- a/src/dorkbox/network/handshake/ServerHandshake.kt +++ b/src/dorkbox/network/handshake/ServerHandshake.kt @@ -25,12 +25,11 @@ import dorkbox.network.aeron.mediaDriver.ServerUdpPairedDriver import dorkbox.network.connection.Connection import dorkbox.network.connection.ConnectionParams import dorkbox.network.connection.EndPoint +import dorkbox.network.connection.EventDispatcher import dorkbox.network.connection.ListenerManager import dorkbox.network.connection.PublicKeyValidationState import dorkbox.network.exceptions.AllocationException import io.aeron.Publication -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import mu.KLogger import net.jodah.expiringmap.ExpirationPolicy @@ -136,7 +135,9 @@ internal class ServerHandshake( } // before we finish creating the connection, we initialize it (in case there needs to be logic that happens-before `onConnect` calls occur - listenerManager.notifyInit(existingConnection) + runBlocking { + listenerManager.notifyInit(existingConnection) + } // this enables the connection to start polling for messages server.addConnection(existingConnection)