Created
May 11, 2025 12:52
-
-
Save VovaStelmashchuk/3ebb974f18764cf6a9a1e04036d7dec7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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