Skip to content

Commit 4853b4a

Browse files
committed
fix(RimeDispatcher): offer empty to queue when stop to avoid blocked by taking
1 parent 23d7518 commit 4853b4a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

app/src/main/java/com/osfans/trime/core/RimeDispatcher.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class RimeDispatcher(
5555
}
5656

5757
override fun toString(): String = "WrappedRunnable[${name ?: hashCode()}]"
58+
59+
companion object {
60+
val Empty = WrappedRunnable({}, "Empty")
61+
}
5862
}
5963

6064
companion object {
@@ -105,6 +109,7 @@ class RimeDispatcher(
105109
Timber.i("RimeDispatcher stop()")
106110
return if (isRunning.compareAndSet(true, false)) {
107111
runBlocking {
112+
queue.offer(WrappedRunnable.Empty)
108113
mutex.withLock {
109114
val rest = mutableListOf<WrappedRunnable>()
110115
queue.drainTo(rest)
@@ -123,6 +128,6 @@ class RimeDispatcher(
123128
if (!isRunning.get()) {
124129
throw IllegalStateException("Dispatcher is not in running state!")
125130
}
126-
queue.put(WrappedRunnable(block))
131+
queue.offer(WrappedRunnable(block))
127132
}
128133
}

0 commit comments

Comments
 (0)