Merge pull request #116 from InsanusMokrassar/0.8.5

0.8.5
This commit is contained in:
InsanusMokrassar 2021-11-27 01:00:18 +06:00 committed by GitHub
commit ca27cb3f82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -1,5 +1,10 @@
# Changelog
## 0.8.5
* `Common`:
* `repeatOnFailure`
## 0.8.4
* `Ktor`:

View File

@ -0,0 +1,21 @@
package dev.inmo.micro_utils.common
/**
* Executes the given [action] until getting of successful result specified number of [times].
*
* A zero-based index of current iteration is passed as a parameter to [action].
*/
inline fun <R> repeatOnFailure(
times: Int,
onEachFailure: (Throwable) -> Unit = {},
action: (Int) -> R
): Optional<R> {
repeat(times) {
runCatching {
action(it)
}.onFailure(onEachFailure).onSuccess {
return Optional.presented(it)
}
}
return Optional.absent()
}

View File

@ -45,5 +45,5 @@ dokka_version=1.5.31
# Project data
group=dev.inmo
version=0.8.4
android_code_version=84
version=0.8.5
android_code_version=85