标签: kotlin-coroutine-channel

第一次发出 kotlin 协程后,MutableStateFlow 不发出值

这是我的 FirebaseOTPVerificationOperation 类,其中定义了我的 MutableStateFlow 属性,并更改了值,

    @ExperimentalCoroutinesApi
class FirebaseOTPVerificationOperation @Inject constructor(
    private val activity: Activity,
    val logger: Logger
) {
    private val _phoneAuthComplete = MutableStateFlow<PhoneAuthCredential?>(null)
    val phoneAuthComplete: StateFlow<PhoneAuthCredential?>
        get() = _phoneAuthComplete

    private val _phoneVerificationFailed = MutableStateFlow<String>("")
    val phoneVerificationFailed: StateFlow<String>
        get() = _phoneVerificationFailed

    private val _phoneCodeSent = MutableStateFlow<Boolean?>(null)
    val phoneCodeSent: StateFlow<Boolean?>
        get() = _phoneCodeSent

    private val _phoneVerificationSuccess = MutableStateFlow<Boolean?>(null)
    val phoneVerificationSuccess: StateFlow<Boolean?>
        get() = _phoneVerificationSuccess

    fun resendPhoneVerificationCode(phoneNumber: String) {
        _phoneVerificationFailed.value = "ERROR_RESEND"
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的视图模式,我在那里监听 stateflow 属性的变化,如下所示,

class OTPVerificationViewModal @AssistedInject constructor(
    private …
Run Code Online (Sandbox Code Playgroud)

kotlin kotlin-coroutines kotlin-coroutines-flow kotlin-coroutine-channel

14
推荐指数
4
解决办法
8666
查看次数

Send 和 Offer 之间的 Kotlin Channels 使用差异

通道有两个功能允许我们向其中发送事件。 Sendoffer

我想更好地理解两者之间的区别。

我有一些说法想核实一下是否属实。

  • Send是一个挂起函数。什么会让我的代码(而不是线程)等待它完成。因此,在内部事件send完成/取消后,它会继续运行。或者它只会挂起,直到我可以对事件进行排队/接收它?
  • 这意味着,如果我send从一个通道使用到另一个通道,第一个通道将被阻塞,直到第二个通道可以接收/排队?
  • 如果我有一个Rendezvous Channel 并且它已经在运行某些东西(例如挂起时,等待 API),并且我有offer一个新的事件。这会引发offer异常吗?导致频道收不到?

如果您知道任何其他主要区别,我会很高兴知道。

提前致谢

channel kotlin kotlin-coroutines kotlin-coroutine-channel

5
推荐指数
1
解决办法
2689
查看次数