簡體   English   中英

如何從構建流中發出價值 object

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM