Skip to content

Commit

Permalink
Release 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergej Shafarenka committed Sep 19, 2024
1 parent 502230c commit 1cfe2a8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transform : Any> {
private val channel = Channel<Transform>(capacity = 64)
Expand All @@ -16,8 +18,11 @@ public abstract class Router<Transform : Any> {
}

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"
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -96,8 +85,11 @@ private class DefaultMutableStateHolder<S : Any>(
)

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"
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ plugins {

allprojects {
group = "de.halfbit"
version = "0.5"
version = "0.6"
}

0 comments on commit 1cfe2a8

Please sign in to comment.