From 1cfe2a8e181854426f53074421fa21cc06796e42 Mon Sep 17 00:00:00 2001 From: Sergej Shafarenka Date: Thu, 19 Sep 2024 14:36:47 +0200 Subject: [PATCH] Release 0.6 --- README.md | 1 + .../de/halfbit/componental/router/Router.kt | 11 +++++++--- .../halfbit/componental/state/StateHolder.kt | 22 ++++++------------- .../main/kotlin/root.publication.gradle.kts | 2 +- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 107b313..f0e0a92 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ dependencies { # Release Notes +* 0.6 Better handling of closed channels * 0.5 Improve Toast API and UI, bump to Kotlin 2.0.20 * 0.4 Refine Stack and Slot API and their implementations * 0.3 Add BackNavigation diff --git a/componental/src/commonMain/kotlin/de/halfbit/componental/router/Router.kt b/componental/src/commonMain/kotlin/de/halfbit/componental/router/Router.kt index 2830b93..5d1a5cd 100644 --- a/componental/src/commonMain/kotlin/de/halfbit/componental/router/Router.kt +++ b/componental/src/commonMain/kotlin/de/halfbit/componental/router/Router.kt @@ -2,7 +2,9 @@ package de.halfbit.componental.router import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.onCompletion public abstract class Router { private val channel = Channel(capacity = 64) @@ -16,8 +18,11 @@ public abstract class Router { } public fun route(transform: Transform) { - if (channel.trySend(transform).isFailure) { - throw IllegalStateException("Failed to schedule transform") + val result = channel.trySend(transform) + if (result.isFailure && !result.isClosed) { + throw IllegalStateException( + "Failed to schedule transform to a not closed channel" + ) } } } diff --git a/componental/src/commonMain/kotlin/de/halfbit/componental/state/StateHolder.kt b/componental/src/commonMain/kotlin/de/halfbit/componental/state/StateHolder.kt index 5c03677..ee001f3 100644 --- a/componental/src/commonMain/kotlin/de/halfbit/componental/state/StateHolder.kt +++ b/componental/src/commonMain/kotlin/de/halfbit/componental/state/StateHolder.kt @@ -2,20 +2,9 @@ package de.halfbit.componental.state import de.halfbit.componental.ComponentContext import de.halfbit.componental.coroutines.ComponentalDispatchers -import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.TimeoutCancellationException +import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.first -import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.flow.onCompletion -import kotlinx.coroutines.flow.stateIn -import kotlinx.coroutines.launch -import kotlinx.coroutines.withTimeout +import kotlinx.coroutines.flow.* import kotlin.reflect.KClass import kotlin.reflect.cast @@ -96,8 +85,11 @@ private class DefaultMutableStateHolder( ) override fun updateState(reducer: (S) -> S) { - if (channel.trySend(reducer).isFailure) { - throw IllegalStateException("Failed to schedule reducer") + val result = channel.trySend(reducer) + if (result.isFailure && !result.isClosed) { + throw IllegalStateException( + "Failed to schedule reducer to a not closed channel" + ) } } diff --git a/convention-plugins/src/main/kotlin/root.publication.gradle.kts b/convention-plugins/src/main/kotlin/root.publication.gradle.kts index 1406b18..80c24a3 100644 --- a/convention-plugins/src/main/kotlin/root.publication.gradle.kts +++ b/convention-plugins/src/main/kotlin/root.publication.gradle.kts @@ -4,5 +4,5 @@ plugins { allprojects { group = "de.halfbit" - version = "0.5" + version = "0.6" }