Reference of existing list is kept before dispatching into new threads
This commit is contained in:
parent
9a3e49bca4
commit
3a07b6bf86
@ -390,8 +390,8 @@ internal class ListenerManager<CONNECTION: Connection>(private val logger: KLogg
|
|||||||
* NOTE: This is run on the EventDispatch!
|
* NOTE: This is run on the EventDispatch!
|
||||||
*/
|
*/
|
||||||
fun notifyConnect(connection: CONNECTION, onCompleteFunction: () -> Unit = {}) {
|
fun notifyConnect(connection: CONNECTION, onCompleteFunction: () -> Unit = {}) {
|
||||||
EventDispatcher.CONNECT.launch {
|
|
||||||
val list = onConnectList.value
|
val list = onConnectList.value
|
||||||
|
EventDispatcher.CONNECT.launch {
|
||||||
list.forEach {
|
list.forEach {
|
||||||
try {
|
try {
|
||||||
it(connection)
|
it(connection)
|
||||||
@ -414,19 +414,18 @@ internal class ListenerManager<CONNECTION: Connection>(private val logger: KLogg
|
|||||||
* NOTE: This is run on the EventDispatch!
|
* NOTE: This is run on the EventDispatch!
|
||||||
*/
|
*/
|
||||||
fun notifyDisconnect(connection: Connection) {
|
fun notifyDisconnect(connection: Connection) {
|
||||||
EventDispatcher.DISCONNECT.launch {
|
|
||||||
connection.notifyDisconnect()
|
connection.notifyDisconnect()
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
directNotifyDisconnect(connection as CONNECTION)
|
directNotifyDisconnect(connection as CONNECTION)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is invoked by either a GLOBAL listener manager, or for a SPECIFIC CONNECTION listener manager.
|
* This is invoked by either a GLOBAL listener manager, or for a SPECIFIC CONNECTION listener manager.
|
||||||
*/
|
*/
|
||||||
suspend fun directNotifyDisconnect(connection: CONNECTION) {
|
fun directNotifyDisconnect(connection: CONNECTION) {
|
||||||
val list = onDisconnectList.value
|
val list = onDisconnectList.value
|
||||||
|
EventDispatcher.DISCONNECT.launch {
|
||||||
list.forEach {
|
list.forEach {
|
||||||
try {
|
try {
|
||||||
it(connection)
|
it(connection)
|
||||||
@ -437,6 +436,7 @@ internal class ListenerManager<CONNECTION: Connection>(private val logger: KLogg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -449,8 +449,8 @@ internal class ListenerManager<CONNECTION: Connection>(private val logger: KLogg
|
|||||||
fun notifyError(connection: CONNECTION, exception: Throwable) {
|
fun notifyError(connection: CONNECTION, exception: Throwable) {
|
||||||
logger.error("Error with connection $connection", exception)
|
logger.error("Error with connection $connection", exception)
|
||||||
|
|
||||||
EventDispatcher.ERROR.launch {
|
|
||||||
val list = onErrorList.value
|
val list = onErrorList.value
|
||||||
|
EventDispatcher.ERROR.launch {
|
||||||
list.forEach {
|
list.forEach {
|
||||||
try {
|
try {
|
||||||
it(connection, exception)
|
it(connection, exception)
|
||||||
@ -471,8 +471,8 @@ internal class ListenerManager<CONNECTION: Connection>(private val logger: KLogg
|
|||||||
fun notifyError(exception: Throwable) {
|
fun notifyError(exception: Throwable) {
|
||||||
logger.error("Global error", exception)
|
logger.error("Global error", exception)
|
||||||
|
|
||||||
EventDispatcher.ERROR.launch {
|
|
||||||
val list = onErrorGlobalList.value
|
val list = onErrorGlobalList.value
|
||||||
|
EventDispatcher.ERROR.launch {
|
||||||
list.forEach {
|
list.forEach {
|
||||||
try {
|
try {
|
||||||
it(exception)
|
it(exception)
|
||||||
|
Loading…
Reference in New Issue
Block a user