From 6763e5c4c6de3f5a18a9409ebe53a858d8b25355 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 26 Nov 2021 19:32:52 +0600 Subject: [PATCH 1/3] start 0.8.5 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54b0a346e3e..6c9d5307274 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.8.5 + ## 0.8.4 * `Ktor`: diff --git a/gradle.properties b/gradle.properties index 0fbc652493f..22103b0dee3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 From 527a2a91accf2953274c8c4ac2e77731ecfa912e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 26 Nov 2021 19:45:59 +0600 Subject: [PATCH 2/3] repeatOnFailure --- CHANGELOG.md | 3 +++ .../micro_utils/common/RepeatOnFailure.kt | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 common/src/commonMain/kotlin/dev/inmo/micro_utils/common/RepeatOnFailure.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c9d5307274..3daac0f5929 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.8.5 +* `Common`: + * `repeatOnFailure` + ## 0.8.4 * `Ktor`: diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/RepeatOnFailure.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/RepeatOnFailure.kt new file mode 100644 index 00000000000..6a396499fc7 --- /dev/null +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/RepeatOnFailure.kt @@ -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 repeatOnFailure( + times: Int, + crossinline onEachFailure: (Throwable) -> Unit = {}, + crossinline action: (Int) -> R +): Optional { + repeat(times) { + runCatching { + action(it) + }.onFailure(onEachFailure).onSuccess { + return Optional.presented(it) + } + } + return Optional.absent() +} From 3a5771a0cc810978190ffe158ebada21e51d0fe0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 26 Nov 2021 23:07:00 +0600 Subject: [PATCH 3/3] Update RepeatOnFailure.kt --- .../kotlin/dev/inmo/micro_utils/common/RepeatOnFailure.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/RepeatOnFailure.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/RepeatOnFailure.kt index 6a396499fc7..409df8d2e98 100644 --- a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/RepeatOnFailure.kt +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/RepeatOnFailure.kt @@ -7,8 +7,8 @@ package dev.inmo.micro_utils.common */ inline fun repeatOnFailure( times: Int, - crossinline onEachFailure: (Throwable) -> Unit = {}, - crossinline action: (Int) -> R + onEachFailure: (Throwable) -> Unit = {}, + action: (Int) -> R ): Optional { repeat(times) { runCatching {