Skip to content

Instantly share code, notes, and snippets.

@VovaStelmashchuk
Created May 11, 2025 12:52
Show Gist options
  • Save VovaStelmashchuk/3ebb974f18764cf6a9a1e04036d7dec7 to your computer and use it in GitHub Desktop.
Save VovaStelmashchuk/3ebb974f18764cf6a9a1e04036d7dec7 to your computer and use it in GitHub Desktop.
suspend fun CoroutineScope.badFoo() {
launch {
delay(1.seconds)
}
}
fun CoroutineScope.goodFoo() {
launch {
delay(1.seconds)
}
}
suspend fun badObserveSignals(): Flow<Unit> {
val pollingInterval = getPollingInterval() // Done outside of the flow builder block.
return flow {
while (true) {
delay(pollingInterval)
emit(Unit)
}
}
}
fun goodObserveSignals(): Flow<Unit> {
return flow {
val pollingInterval = getPollingInterval() // Moved into the flow builder block.
while (true) {
delay(pollingInterval)
emit(Unit)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment