If we close the event poller WHILE ON the event poller, re-dispatch the close event to the CLOSE dispatch

This commit is contained in:
Robinson 2023-08-07 19:53:59 -06:00
parent 08d58fd6fd
commit 6dc7e6bc41
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
1 changed files with 9 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import dorkbox.bytes.ByteArrayWrapper
import dorkbox.collections.ConcurrentIterator
import dorkbox.network.Configuration
import dorkbox.network.connection.EndPoint
import dorkbox.network.connection.EventDispatcher
import dorkbox.util.NamedThreadFactory
import kotlinx.atomicfu.atomic
import kotlinx.coroutines.*
@ -190,6 +191,14 @@ internal class EventPoller {
* Waits for all events to finish running
*/
suspend fun close(logger: KLogger, endPoint: EndPoint<*>) {
// make sure that we close on the CLOSE dispatcher if we run on the poll dispatcher!
if (inDispatch()) {
EventDispatcher.CLOSE.launch {
close(logger, endPoint)
}
return
}
mutex.withLock {
logger.debug { "Requesting close for the Network Event Poller..." }