Sean McQuillan
May 25, 2019 · 1 min read

This is definitely something that is being looked into (see:

It turns out it’s actually a fairly complicated problem — what exactly does it mean for a CoroutineScope (or Dispatcher) to be idle? To understand a bit of the problem: it’s OK to write an infinite loop like this in a coroutine to create a timer:

val secondsSinceStarted = liveData {
var seconds = 0
while(true) {

This will cleanup correctly in viewModelScope, but it will never be fully “idle.”

There’s quite a few ideas on the issue I linked above (and some working code). Definitely take a look!

Sean McQuillan

Written by

Android Developer Advocate @Google

More From Medium

More from Sean McQuillan

More from Sean McQuillan

Top on Medium

Ed Yong
Mar 25 · 22 min read


Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade