I am practicing Coroutines Channel and I'm wondering why does the repository.getAllRates() did not trigger even my code reached the sellCurrencyChannel.send(CurrencyRate(“”, 0.0))? I'm also suspecting that the sellCurrencyChannel.send() was unsuccessful.
private val sellCurrencyChannel = Channel<CurrencyRate>()
val sellCurrency = sellCurrencyChannel.receiveAsFlow()
val sellAmount: LiveData<Double>? = null
val allUserBalance = repository.getAllUserBalance()
.flatMapLatest {
if (it.isNullOrEmpty()) {
repository.setUserBalance(
UserBalance(
"EUR",
1000.0
)
)
} else {
viewModelScope.launch {
sellCurrencyChannel.send(CurrencyRate("", 0.0))
}
}
return@flatMapLatest repository.getAllUserBalance()
}
.stateIn(
viewModelScope,
SharingStarted.Lazily,
null
)
val allRates = sellCurrency.flatMapLatest { sellCurrency ->
repository.getAllRates(
sellCurrency.currency,
onAPISuccess = {
},
onAPIFailed = {
viewModelScope.launch {
eventChannel.send(Event.ShowErrorMessage(it))
}
}
)
}.stateIn(viewModelScope, SharingStarted.Lazily, null)