我的問題是我們如何從構建的流物件中發出一個值,如下所示:
class Sample {
var flow: Flow<Object> = null
fun sendRequest(){
flow = flow{}
requestWrapper.flowResponse = flow
}
fun getResponse(){
// I want to emit data here with built flow object on
// requestWrapper like this
requestWrapper.flowResponse.emit()
}
}
這個問題有什么可能的解決方案嗎?
uj5u.com熱心網友回復:
您可以使用MutableSharedFlow
在您的情況下發出值:
class Sample {
var flow: MutableSharedFlow<Object>? = MutableSharedFlow(...)
fun sendRequest(){
requestWrapper.flowResponse = flow
}
fun getResponse(){
// I want to emit data here with built flow object on
// requestWrapper like this
requestWrapper.flowResponse?.tryEmit(...)
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/481010.html
上一篇:“Gradle任務assembleDebug失敗,退出代碼1”,因為“找不到或加載主類org.gradle.wrapper.GradleWrapperMain”