Skip to content

Commit 19ebfb1

Browse files
committed
refactor: migrate to suspendCancellableCoroutine
1 parent 262abd4 commit 19ebfb1

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ package com.osfans.trime.core
99
import kotlinx.coroutines.CoroutineScope
1010
import kotlinx.coroutines.SupervisorJob
1111
import kotlinx.coroutines.cancelChildren
12+
import kotlinx.coroutines.suspendCancellableCoroutine
1213
import java.util.concurrent.ConcurrentLinkedQueue
1314
import kotlin.coroutines.Continuation
1415
import kotlin.coroutines.CoroutineContext
1516
import kotlin.coroutines.resume
16-
import kotlin.coroutines.suspendCoroutine
1717

1818
class RimeLifecycleRegistry : RimeLifecycle {
1919

@@ -127,7 +127,7 @@ private class StateDelegate(
127127
private var continuation: Continuation<Unit>? = null
128128

129129
suspend fun <T> run(block: suspend CoroutineScope.() -> T): T {
130-
suspendCoroutine { continuation = it }
130+
suspendCancellableCoroutine { continuation = it }
131131
lifecycle.removeObserver(observer)
132132
return block(lifecycle.lifecycleScope)
133133
}

app/src/main/java/com/osfans/trime/ime/bar/InputBarDelegate.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ import kotlinx.coroutines.async
4646
import kotlinx.coroutines.awaitAll
4747
import kotlinx.coroutines.delay
4848
import kotlinx.coroutines.launch
49+
import kotlinx.coroutines.suspendCancellableCoroutine
4950
import org.kodein.di.instance
5051
import splitties.dimensions.dp
5152
import splitties.views.dsl.core.add
5253
import splitties.views.dsl.core.lParams
5354
import splitties.views.dsl.core.matchParent
5455
import java.util.concurrent.Executor
5556
import kotlin.coroutines.resume
56-
import kotlin.coroutines.suspendCoroutine
5757

5858
class InputBarDelegate : InputBroadcastReceiver {
5959
private val di = InputDependencyManager.getInstance().di
@@ -333,7 +333,7 @@ class InputBarDelegate : InputBroadcastReceiver {
333333
}
334334

335335
@RequiresApi(Build.VERSION_CODES.R)
336-
private suspend fun inflateInlineContentView(suggestion: InlineSuggestion): InlineContentView? = suspendCoroutine { c ->
336+
private suspend fun inflateInlineContentView(suggestion: InlineSuggestion): InlineContentView? = suspendCancellableCoroutine { c ->
337337
// callback view might be null
338338
suggestion.inflate(context, suggestionSize, directExecutor) { v ->
339339
c.resume(v)

0 commit comments

Comments
 (0)