File tree Expand file tree Collapse file tree
src/main/kotlin/cn/coostack/cooparticlesapi/scheduler Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package cn.coostack.cooparticlesapi.scheduler
22
3+ import java.util.concurrent.ConcurrentLinkedQueue
34import kotlin.math.sin
45
56class CooScheduler {
6- internal val ticks = HashSet <TickRunnable >()
7+ internal val ticks = ConcurrentLinkedQueue <TickRunnable >()
8+ internal val taskQueue = ConcurrentLinkedQueue <TickRunnable >()
79 internal fun doTick () {
810 val iterator = ticks.iterator()
911 while (iterator.hasNext()) {
@@ -13,6 +15,8 @@ class CooScheduler {
1315 iterator.remove()
1416 }
1517 }
18+ ticks.addAll(taskQueue)
19+ taskQueue.clear()
1620 }
1721
1822 /* *
@@ -22,7 +26,7 @@ class CooScheduler {
2226 val tick = TickRunnable (runnable)
2327 tick.singleDelay = delay
2428 tick.loop()
25- ticks .add(tick)
29+ taskQueue .add(tick)
2630 return tick
2731 }
2832
@@ -32,7 +36,7 @@ class CooScheduler {
3236 fun runTask (delay : Int , runnable : Runnable ): TickRunnable {
3337 val tick = TickRunnable (runnable)
3438 tick.singleDelay = delay
35- ticks .add(tick)
39+ taskQueue .add(tick)
3640 return tick
3741 }
3842
@@ -44,7 +48,7 @@ class CooScheduler {
4448 val tick = TickRunnable (runnable)
4549 tick.maxTick = maxLoopTick
4650 tick.loopTimer()
47- ticks .add(tick)
51+ taskQueue .add(tick)
4852 return tick
4953 }
5054
@@ -59,7 +63,7 @@ class CooScheduler {
5963 tick.maxTick = maxLoopTick
6064 tick.singleDelay = preDelay
6165 tick.loopTimer()
62- ticks .add(tick)
66+ taskQueue .add(tick)
6367 return tick
6468 }
6569
You can’t perform that action at this time.
0 commit comments