Migrate to suspendCancellableCoroutine

This commit is contained in:
Rocka 2026-05-16 20:32:31 +08:00
parent 4fcd43610d
commit e9e5e5b757
No known key found for this signature in database
GPG Key ID: 28031158FFDD6853
2 changed files with 5 additions and 6 deletions

View File

@ -8,11 +8,11 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import java.util.concurrent.ConcurrentLinkedQueue
import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
class FcitxLifecycleRegistry : FcitxLifecycle {
@ -138,9 +138,8 @@ private class AtStateHelper(val lifecycle: FcitxLifecycle, val state: FcitxLifec
private var continuation: Continuation<Unit>? = null
suspend fun <T> run(block: suspend CoroutineScope.() -> T): T {
suspendCoroutine { continuation = it }
suspendCancellableCoroutine { continuation = it }
lifecycle.removeObserver(observer)
return block(lifecycle.lifecycleScope)
}
}

View File

@ -25,6 +25,7 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import org.fcitx.fcitx5.android.R
import org.fcitx.fcitx5.android.core.CapabilityFlag
import org.fcitx.fcitx5.android.core.CapabilityFlags
@ -76,13 +77,12 @@ import splitties.views.dsl.core.lParams
import splitties.views.dsl.core.matchParent
import java.util.concurrent.Executor
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlin.math.PI
import kotlin.math.abs
import kotlin.math.atan2
import kotlin.math.cos
import kotlin.math.hypot
import kotlin.math.min
import kotlin.math.PI
import kotlin.math.sin
class KawaiiBarComponent : UniqueViewComponent<KawaiiBarComponent, FrameLayout>(),
@ -538,7 +538,7 @@ class KawaiiBarComponent : UniqueViewComponent<KawaiiBarComponent, FrameLayout>(
@RequiresApi(Build.VERSION_CODES.R)
private suspend fun inflateInlineContentView(suggestion: InlineSuggestion): InlineContentView? {
return suspendCoroutine { c ->
return suspendCancellableCoroutine { c ->
// callback view might be null
suggestion.inflate(context, suggestionSize, directExecutor) { v ->
c.resume(v)