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,8 +370,7 @@ 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 {
suspend fun notifyInit(connection: CONNECTION) {
onInitList.value.forEach {
try {
it(connection)
@ -383,7 +381,6 @@ internal class ListenerManager<CONNECTION: Connection>(private val logger: KLogg
}
}
}
}
/**
* Invoked when a connection is connected to a remote address.

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
runBlocking {
listenerManager.notifyInit(existingConnection)
}
// this enables the connection to start polling for messages
server.addConnection(existingConnection)