Skip to content

Instantly share code, notes, and snippets.

@oogatta
Last active September 14, 2020 16:21
Show Gist options
  • Save oogatta/0e43b13c1adcd14b720d73a27e8e7b16 to your computer and use it in GitHub Desktop.
Save oogatta/0e43b13c1adcd14b720d73a27e8e7b16 to your computer and use it in GitHub Desktop.
kotlin flow retrying forever (suspending functions)
// 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