ursus
04/18/2022, 1:13 AMprivate var running = true
scope.launch {
flow {
var counter = 0
while (true) {
Log.d("Default", "waiting...")
while (running) {
delay(200)
emit(counter++)
}
}
}
.collect {
Log.d("Default", "value=$it")
}
}
fun pause() {
running = false
}
fun resume() {
running = true
}
how would I best implement pausing/resuming, without spamming “waiting…” when running == false
? i.e make it suspend and not retry the while condition so fast?Dan Fingal-Surma
04/18/2022, 2:21 AM