mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-23 02:28:47 +00:00
commit
ca27cb3f82
@ -1,5 +1,10 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.8.5
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* `repeatOnFailure`
|
||||||
|
|
||||||
## 0.8.4
|
## 0.8.4
|
||||||
|
|
||||||
* `Ktor`:
|
* `Ktor`:
|
||||||
|
@ -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()
|
||||||
|
}
|
@ -45,5 +45,5 @@ dokka_version=1.5.31
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.8.4
|
version=0.8.5
|
||||||
android_code_version=84
|
android_code_version=85
|
||||||
|
Loading…
Reference in New Issue
Block a user