Last active
September 14, 2020 16:21
-
-
Save oogatta/0e43b13c1adcd14b720d73a27e8e7b16 to your computer and use it in GitHub Desktop.
kotlin flow retrying forever (suspending functions)
This file contains 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
// suspending functions | |
flow { | |
emit(doSomethingSuspending()) | |
}.mapNotNull { | |
if (it == null) { | |
throw Exception() | |
} | |
it | |
}.retryWhen { _, _ -> | |
delay(RETRY_INTERVAL) | |
true | |
}.collect { // or .single() | |
// do something | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment