Last active
September 14, 2020 16:21
-
-
Save oogatta/c60cfc4af66947d276c8cd83d59a934c to your computer and use it in GitHub Desktop.
kotlin flow retrying forever (callbacks)
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
// 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