Log events properly in EventChannelImpl

This commit is contained in:
Him188 2022-05-13 14:56:17 +01:00
parent 4c28913a27
commit 1d2ae12196

View File

@ -37,7 +37,7 @@ internal annotation class DangerousEventChannelImplConstructor
internal open class EventChannelImpl<E : Event> @DangerousEventChannelImplConstructor constructor( internal open class EventChannelImpl<E : Event> @DangerousEventChannelImplConstructor constructor(
baseEventClass: KClass<out E>, defaultCoroutineContext: CoroutineContext = EmptyCoroutineContext baseEventClass: KClass<out E>, defaultCoroutineContext: CoroutineContext = EmptyCoroutineContext
) : EventChannel<E>(baseEventClass, defaultCoroutineContext) { ) : EventChannel<E>(baseEventClass, defaultCoroutineContext) {
val eventListeners = EventListeners() private val eventListeners = EventListeners()
// drop any unsubscribed events // drop any unsubscribed events
private val flow = MutableSharedFlow<Event>(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST) private val flow = MutableSharedFlow<Event>(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
@ -48,6 +48,7 @@ internal open class EventChannelImpl<E : Event> @DangerousEventChannelImplConstr
suspend fun callListeners(event: Event) { suspend fun callListeners(event: Event) {
event as AbstractEvent event as AbstractEvent
logEvent(event)
eventListeners.callListeners(event) eventListeners.callListeners(event)
flow.emit(event) flow.emit(event)
} }
@ -86,10 +87,7 @@ internal open class EventChannelImpl<E : Event> @DangerousEventChannelImplConstr
} }
event.broadCastLock.withLock { event.broadCastLock.withLock {
event._intercepted = false event._intercepted = false
@Suppress("DEPRECATION") callListeners(event)
if (EventDisabled) return@withLock
logEvent(event)
eventListeners.callListeners(event)
} }
return event return event