Skip to content

Instantly share code, notes, and snippets.

@oogatta
Last active September 14, 2020 16:21
Show Gist options
  • Save oogatta/c60cfc4af66947d276c8cd83d59a934c to your computer and use it in GitHub Desktop.
Save oogatta/c60cfc4af66947d276c8cd83d59a934c to your computer and use it in GitHub Desktop.
kotlin flow retrying forever (callbacks)
// kinds of callbacks
channelFlow {
do.something(object: SomethingListher {
override fun onSomething(something: Something?) {
send(something)
}
})
}.mapNotNull {
if (it == null) {
throw Exception()
}
it
}.retryWhen { _, _ ->
delay(5 * 1000L)
true
}.collect { // or .single()
// finally do something meaningful
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment