Skip to content

Commit 4a3c76c

Browse files
committed
🐛(core) dispatchYield警告刷屏
1 parent f1dd9f8 commit 4a3c76c

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

scripts/coreMindustry/lib/DispatcherExt.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package coreMindustry.lib
22

33
import arc.Core
4+
import arc.util.Interval
45
import cf.wayzer.scriptAgent.thisContextScript
56
import kotlinx.coroutines.*
67
import java.util.concurrent.ConcurrentLinkedQueue
@@ -16,6 +17,7 @@ object MindustryDispatcher : CoroutineDispatcher() {
1617

1718
@Volatile
1819
private var inBlocking = false
20+
private val warnTimer = Interval()
1921

2022
init {
2123
Core.app.post {
@@ -37,9 +39,10 @@ object MindustryDispatcher : CoroutineDispatcher() {
3739

3840
@OptIn(InternalCoroutinesApi::class)
3941
override fun dispatchYield(context: CoroutineContext, block: Runnable) {
40-
thisContextScript().logger.log(
41-
Level.WARNING, "avoid use yield() in Dispatchers.game, use nextTick instead", Exception()
42-
)
42+
if (warnTimer[10 * 60f])
43+
thisContextScript().logger.log(
44+
Level.WARNING, "avoid use yield() in Dispatchers.game, use nextTick instead", Exception()
45+
)
4346
Core.app.post(block)
4447
}
4548

0 commit comments

Comments
 (0)