```private var running = true scope.launch { ...
# coroutines
u
Copy code
private 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?
🧵 1