If I’m using this `liveData` block, do I need to s...
# coroutines
s
If I’m using this
liveData
block, do I need to scope it to
viewModelScope
, or is that handled automatically? Specifically I’m concerned about cancelling the job, does that still need to be done with this method?
Copy code
val testLangLiveData : LiveData<String?> = liveData {
        viewModelScope.launch {
            try {
                emit(repository.getUser().data.attributes?.locale)
            } catch (e: Exception) {

            }
        }
    }
a
You don't need the inner launch, once there are no more observers the job executing the block is cancelled for you
🙌 1
s
Got it- thanks Adam!
👍 1