hardStudy question · answer published in Kotlin interview questions, so no pointskotlin-coroutineserror-handling
Polling loop that ignores cancellation
After the ViewModel is cleared, logs show this loop still logging errors over and over. Why?
viewModelScope.launch {
while (true) {
try {
delay(1000)
poll()
} catch (e: Exception) {
log(e)
}
}
}Discussion 0
Join free to post in the discussion.
Related questions
- launch vs async in coroutinesMobile App Developer
- What try? returnsMobile App Developer
- viewModelScope after the screen closesMobile App Developer
- Blocking file read in a coroutineMobile App Developer
- Result in a completion handlerMobile App Developer
- Collecting a cold Flow twiceMobile App Developer
- One failing request in coroutineScopeMobile App Developer
- Handler on a child coroutineMobile App Developer