David Corrado
10/07/2022, 4:19 PMstreetsofboston
10/07/2022, 4:37 PMDavid Corrado
10/07/2022, 5:21 PMDavid Corrado
10/07/2022, 5:22 PMDavid Corrado
10/07/2022, 5:26 PMvar stateFlow = MutableStateFlow(runBlocking { loginSessionFlow().first() })
loginSessionFlow().collect {
stateFlow.emit(it)
}
Is above what I was thinking but I would either I am thinking about things wrong or there may be a better way to do thisNick Allen
10/08/2022, 12:05 AMstateIn
Nick Allen
10/08/2022, 4:31 AMstateIn
will work for places where you want the data immediately but because you are dealing with data where there is no immediate value available initially, any code that needs data immediately will need to contend with the possibility that the data was not loaded yet. This can often be represented with an initial null value.
For places where you can block to get the data, you can call runBlocking
there and then use the suspend APIs to get the value.
Calling runBlocking
to create the MutableStateFlow
is likely to cause issues since anything using it (presumable coroutines) will then be dependent on blocking code.