Skip to content

Commit

Permalink
Merge pull request #493
Browse files Browse the repository at this point in the history
SimpleEventListenerManager 实现中增加默认调度器
  • Loading branch information
ForliyScarlet authored Nov 5, 2022
2 parents eda775c + f2d311c commit 1afe1b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public interface CoreListenerManager : SimpleEventListenerManager
* 立即返回一个 [AsyncEventResult].
*
*
*
* ## 监听函数的解析、缓存与获取
* 在 [SimpleEventListenerManager] 中,真正被执行的监听函数是经过缓存与转化的,它们只会在遇到一个目前缓存中未知的事件类型的时候进行同步转化缓存。
*
Expand All @@ -73,6 +72,8 @@ public interface CoreListenerManager : SimpleEventListenerManager
*
* 但是这存在例外:当存在任何通过 [ContinuousSessionContext] 而注册的持续会话监听函数的时候,[isProcessable] 将会始终得到 `true`。
*
* 需要注意的是, [isProcessable] 的结果并不保证是 **"强可靠"** 的。由于对监听函数动态增删的支持,其内部持有的监听函数集应当保证线程安全,
* 但是不会保证**强一致性**。这可能会导致当一个监听函数被追加的这一**瞬间**,[isProcessable] 仍无法感知到它的存在。
*
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ internal class SimpleEventListenerManagerImpl internal constructor(
LoggerFactory.getLogger("love.forte.simbot.core.event.SimpleEventListenerManagerImpl")

private const val EVENT_KEY_PROCESSABLE_COUNTER_CLEAR_THRESHOLD = 83

/**
* 是否禁用产生内部使用的默认调度器。
*/
private const val DISABLE_DEFAULT_DISPATCHER = "love.forte.simbot.core.SimpleListenerManager.disableDefaultDispatcher"

}

Expand Down Expand Up @@ -213,8 +218,12 @@ internal class SimpleEventListenerManagerImpl internal constructor(

@OptIn(ExperimentalStdlibApi::class, ExperimentalCoroutinesApi::class)
if (context[CoroutineDispatcher] == null) {
// todo configurable
context += Dispatchers.Default.limitedParallelism(16)
if (System.getProperty(DISABLE_DEFAULT_DISPATCHER).toBoolean()) {
// todo configurable
context += Dispatchers.Default.limitedParallelism(Runtime.getRuntime().availableProcessors().coerceAtLeast(16))
} else {
logger.debug("No dispatcher for current simple listener manager, and default dispatcher is disabled.")
}
}

managerCoroutineContext = context
Expand Down

0 comments on commit 1afe1b7

Please sign in to comment.