moved runBlocking to invoking method

This commit is contained in:
Robinson 2023-03-02 19:43:06 +01:00
parent 9d04c3acb1
commit 96b5bcf905
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
2 changed files with 12 additions and 14 deletions

View File

@ -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<CONNECTION: Connection>(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)
}
}
}

View File

@ -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<CONNECTION : Connection>(
}
// 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)