diff --git a/CHANGELOG.md b/CHANGELOG.md index dc926c41013830c6314cb4a2da49c5b0c6829de5..6d364a18ef085978885c7715644f758be65b1c8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed cache did not persist values when there were no cache entry but subscribers for an index (very rare case) - Fix dokka documentation generation +- retryFlow now correctly retries on catching a Throwable ## 4.22.4 diff --git a/trixnity-utils/src/commonMain/kotlin/net/folivo/trixnity/utils/retryFlow.kt b/trixnity-utils/src/commonMain/kotlin/net/folivo/trixnity/utils/retryFlow.kt index d982ac809f2a131842d2f87812978a38ac191672..f411524a5efad38d4c21d8862619e9ab2127be91 100644 --- a/trixnity-utils/src/commonMain/kotlin/net/folivo/trixnity/utils/retryFlow.kt +++ b/trixnity-utils/src/commonMain/kotlin/net/folivo/trixnity/utils/retryFlow.kt @@ -38,7 +38,7 @@ fun retryFlow( emit(RetryFlowResult.Suspend) // ensure, that block is not called before a new value is requested emitAll(flow(block).map { RetryFlowResult.Emit(it) }) retryCounter = 0 - } catch (error: Exception) { + } catch (error: Throwable) { if (error is CancellationException) throw error val retryDelay = diff --git a/trixnity-utils/src/commonTest/kotlin/net/folivo/trixnity/utils/RetryFlowTest.kt b/trixnity-utils/src/commonTest/kotlin/net/folivo/trixnity/utils/RetryFlowTest.kt index d71f6f94c9f11687328f9b9bcadb55207dcb7f91..a49c35273fc0401699e356a951fcc5cff91c3cb8 100644 --- a/trixnity-utils/src/commonTest/kotlin/net/folivo/trixnity/utils/RetryFlowTest.kt +++ b/trixnity-utils/src/commonTest/kotlin/net/folivo/trixnity/utils/RetryFlowTest.kt @@ -29,7 +29,7 @@ class RetryFlowTest : TrixnityBaseTest() { } @Test - fun shouldRetryOnError() = runTest { + fun shouldRetryOnException() = runTest { var attempts = 0 val result = retryFlow { attempts++ @@ -43,6 +43,21 @@ class RetryFlowTest : TrixnityBaseTest() { attempts shouldBe 3 } + @Test + fun shouldRetryOnThrowable() = runTest { + var attempts = 0 + val result = retryFlow { + attempts++ + if (attempts < 3) { + throw Throwable("Test throwable") + } + emit(attempts) + }.take(3).first() + + result shouldBe 3 + attempts shouldBe 3 + } + @Test fun shouldRespectDelayConfig() = runTest { var attempts = 0