![](/img/trans.png)
[英]How do you emit multiple flow values as an object at the repository level?
[英]how to emit value from built flow object
我的問題是我們如何從構建的流 object 中發出一個值,如下所示:
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()
}
}
這個問題有什么可能的解決方案嗎?
您可以使用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(...)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.