24
May
Table of contents Short code example Why use this? My app on the Google play store Resources Programming Android with Kotlin: Achieving Structured Concurrency with Coroutines. Chapter 10 Short code example Here is the code that will allow you to make automatic retries on a flow: fun <T, R : Any> Flow<T>.mapWithRetry( action: suspend (T) -> R, predicate: suspend (R, attempt: Int) -> Boolean ) = map { data -> var attempt = 0L var shallRetry: Boolean var lastValue: R? = null do { val tr = action(data) shallRetry = predicate(tr, (++attempt).toInt()) if (!shallRetry) lastValue = tr } while (shallRetry)…