这是我的 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
通道有两个功能允许我们向其中发送事件。
Send和offer。
我想更好地理解两者之间的区别。
我有一些说法想核实一下是否属实。
Send是一个挂起函数。什么会让我的代码(而不是线程)等待它完成。因此,在内部事件send完成/取消后,它会继续运行。或者它只会挂起,直到我可以对事件进行排队/接收它?send从一个通道使用到另一个通道,第一个通道将被阻塞,直到第二个通道可以接收/排队?offer一个新的事件。这会引发offer异常吗?导致频道收不到?如果您知道任何其他主要区别,我会很高兴知道。
提前致谢