kotlin-coroutines

Kotlin, Android, how to debug coroutines correctly?

老子叫甜甜 提交于 2020-12-05 03:53:59
问题 I trying to debug my coroutines, and breakpoints placed into suspend function does't work. Pls help me to understand why. Working with Android Studio. Ok, i launch a coroutine from viewModelScope: viewModelScope.launch(IO) { when(val result = interactor.getAllWords()){...} } In getAllWords() i wrote: override suspend fun getAllWords(): WordResult { val words = mutableListOf<Word>() when (val wordsResult = getAllWordsWithoutFiltersApplying()) {} ... return getWordsWithSelectedPattern() I have

Kotlin, Android, how to debug coroutines correctly?

◇◆丶佛笑我妖孽 提交于 2020-12-05 03:47:42
问题 I trying to debug my coroutines, and breakpoints placed into suspend function does't work. Pls help me to understand why. Working with Android Studio. Ok, i launch a coroutine from viewModelScope: viewModelScope.launch(IO) { when(val result = interactor.getAllWords()){...} } In getAllWords() i wrote: override suspend fun getAllWords(): WordResult { val words = mutableListOf<Word>() when (val wordsResult = getAllWordsWithoutFiltersApplying()) {} ... return getWordsWithSelectedPattern() I have

MutableLiveData: Cannot invoke setValue on a background thread from Coroutine

孤街醉人 提交于 2020-11-25 08:48:34
问题 I'm trying to trigger an update on LiveData from a coroutine: object AddressList: MutableLiveData<List<Address>>() fun getAddressesLiveData(): LiveData<List<Address>> { AddressList.value = listOf() GlobalScope.launch { AddressList.value = getAddressList() } return AddressList } but I get the following error: IllegalStateException: Cannot invoke setValue on a background thread Is there a way to make it work with coroutines? 回答1: Use liveData.postValue(value) instead of liveData.value = value .

MutableLiveData: Cannot invoke setValue on a background thread from Coroutine

亡梦爱人 提交于 2020-11-25 08:47:36
问题 I'm trying to trigger an update on LiveData from a coroutine: object AddressList: MutableLiveData<List<Address>>() fun getAddressesLiveData(): LiveData<List<Address>> { AddressList.value = listOf() GlobalScope.launch { AddressList.value = getAddressList() } return AddressList } but I get the following error: IllegalStateException: Cannot invoke setValue on a background thread Is there a way to make it work with coroutines? 回答1: Use liveData.postValue(value) instead of liveData.value = value .

MutableLiveData: Cannot invoke setValue on a background thread from Coroutine

耗尽温柔 提交于 2020-11-25 08:44:36
问题 I'm trying to trigger an update on LiveData from a coroutine: object AddressList: MutableLiveData<List<Address>>() fun getAddressesLiveData(): LiveData<List<Address>> { AddressList.value = listOf() GlobalScope.launch { AddressList.value = getAddressList() } return AddressList } but I get the following error: IllegalStateException: Cannot invoke setValue on a background thread Is there a way to make it work with coroutines? 回答1: Use liveData.postValue(value) instead of liveData.value = value .