Guarantee that connect occurs AFTER the current close events are finished running before redispatching on the connect dispatcher

This commit is contained in:
Robinson 2023-11-22 09:18:17 +01:00
parent 88bac6ef84
commit 76f42c900c
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
1 changed files with 14 additions and 9 deletions

View File

@ -459,16 +459,21 @@ open class Client<CONNECTION : Connection>(config: ClientConfiguration = ClientC
if (eventDispatch.isDispatch() && !eventDispatch.CONNECT.isDispatch()) { if (eventDispatch.isDispatch() && !eventDispatch.CONNECT.isDispatch()) {
// only re-dispatch if we are on the event dispatch AND it's not the CONNECT one // only re-dispatch if we are on the event dispatch AND it's not the CONNECT one
// if we are on an "outside" thread, then we don't care. // if we are on an "outside" thread, then we don't care.
eventDispatch.CONNECT.launch {
connect( // we have to guarantee that CLOSE finishes running first! If we are already on close, then this will just run after close is finished.
remoteAddress = remoteAddress, eventDispatch.CLOSE.launch {
remoteAddressString = remoteAddressString, eventDispatch.CONNECT.launch {
remoteAddressPrettyString = remoteAddressPrettyString, connect(
port1 = port1, remoteAddress = remoteAddress,
port2 = port2, remoteAddressString = remoteAddressString,
connectionTimeoutSec = connectionTimeoutSec, remoteAddressPrettyString = remoteAddressPrettyString,
reliable = reliable) port1 = port1,
port2 = port2,
connectionTimeoutSec = connectionTimeoutSec,
reliable = reliable)
}
} }
return return
} }