Remove internal EventBroadcast, code cleanup

This commit is contained in:
Him188 2022-05-13 14:57:12 +01:00
parent 1d2ae12196
commit 0c809f4e4c
3 changed files with 5 additions and 17 deletions

View File

@ -154,17 +154,10 @@ public interface CancellableEvent : Event {
*/
@JvmBlockingBridge
public suspend fun <E : Event> E.broadcast(): E {
@OptIn(TestOnly::class)
EventBroadcast.implementation.invoke(this)
Mirai.broadcastEvent(this)
return this
}
// 由测试覆盖
@TestOnly
internal object EventBroadcast {
internal val implementation: suspend (Event) -> Unit = { Mirai.broadcastEvent(it) }
}
/**
* 设置为 `true` 以关闭事件.
* 所有的 `subscribe` 都能正常添加到监听器列表, 但所有的广播都会直接返回.

View File

@ -14,9 +14,6 @@ import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.reflect.KClass
/**
* @since 2.11
*/
@OptIn(DangerousEventChannelImplConstructor::class)
internal class EventChannelToEventDispatcherAdapter<E : Event> private constructor(
baseEventClass: KClass<out E>, defaultCoroutineContext: CoroutineContext = EmptyCoroutineContext

View File

@ -1,10 +1,10 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2022 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.internal.test
@ -18,14 +18,12 @@ import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.test.assertEquals
@OptIn(ExperimentalCoroutinesApi::class)
internal inline fun <reified T : Event, R> assertEventBroadcasts(times: Int = 1, block: () -> R): R {
assertEventBroadcasts<T>(times) {
return block()
}
}
@OptIn(ExperimentalCoroutinesApi::class)
internal inline fun <reified T : Event> assertEventBroadcasts(times: Int = 1, block: () -> Unit): List<T> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }