So I did the sample test for this race condition I...
# coroutines
r
So I did the sample test for this race condition I removed my setupDataCollection function and simply tried to emit data after subscribing and after delay of 6 seconds and it still did not work Still subscription count comes as ZERO
Copy code
class DataApi {
   private val dataUpdates = MutableStateFlow<List<Data>?>(null)

   fun subscribeToDataUpdates(streamId:String, coroutineScope: CoroutineScope) {
     return dataUpdates
   }

   fun sampleInit(scope: CoroutineScope) {
      scope.launch { 
        delay(3000)
        dataUpdates.emit(listOf(data))
      }
   }
}
Copy code
class DataViewModel(private val dataApi): ViewModel() {
 
    fun  loadData(streamid: String) {
       viewModelScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
           dataApi.subscribeToDataUpdates(streamid, viewModelScope).collectLatest {
               // I DO NOT GET UPDATES HERE EMITTED BY `dataUpdates`
           }
       }

       viewModelScope.launch {
            delay(3000)
            dataApi.sampleInit(this)
        }
    }

}