private lateinit var cards: List
fun start() = viewModelScope.launch {
if (!::cards.isInitialized) {
getCards().collect { result ->
result
.doIfSuccess {
cards = it.data
Log.d(TAG, "Received cards")
}
.doIfError {
_errorState.setIfNotEqual(it.exception)
Log.e(TAG, "Cards were not received because of ${it.exception}")
return@collect //
Подробнее здесь: [url]https://stackoverflow.com/questions/67408311/how-to-return-to-launch-inside-of-the-collect[/url]
У меня есть метод, который выглядит так: [code]private lateinit var cards: List
fun start() = viewModelScope.launch { if (!::cards.isInitialized) { getCards().collect { result -> result .doIfSuccess { cards = it.data Log.d(TAG, "Received cards") } .doIfError { _errorState.setIfNotEqual(it.exception) Log.e(TAG, "Cards were not received because of ${it.exception}") return@collect //