Package-level declarations

Types

Link copied to clipboard

Concurrency utilities for state management without external dependencies.

Link copied to clipboard

Thread-safe wrapper for StateContainer implementations.

Functions

Link copied to clipboard
fun <T> StateContainer<T>.compareAndSet(expectedState: T, newState: T): Boolean

Conditionally updates the state only if the current state matches the expected state.

Link copied to clipboard
fun <T> StateContainer<T>.getAndUpdate(updater: (T) -> T): T?

Updates the state and returns the previous state if successful, or null if failed.

Link copied to clipboard
inline fun <T, R : T> StateContainer<T>.getStateAs(): R?

Returns the current state cast to the specified type, or null if not of that type.

Link copied to clipboard
fun <T> StateContainer<T>.isState(predicate: (T) -> Boolean): Boolean

Checks if the state matches a predicate.

Link copied to clipboard
inline fun <T, R : T> StateContainer<T>.isStateType(): Boolean

Returns true if the current state is of the specified type.

Link copied to clipboard
fun <T, R> StateContainer<T>.map(mapper: (T) -> R): R

Maps the current state to a different type.

Link copied to clipboard
fun <T> StateContainer<T>.trySet(newState: T): Boolean

Attempts to set the state to a specific value.

Link copied to clipboard
fun <T> StateContainer<T>.updateAndGet(updater: (T) -> T): T?

Updates the state and returns the new state if successful, or null if failed.

Link copied to clipboard
fun <T> StateContainer<T>.updateAtomic(maxRetries: Int = 10, updater: (T) -> T): StateUpdateResult<T>

Extension function for StateContainer to perform atomic updates.

Link copied to clipboard
suspend fun <T> StateContainer<T>.updateSuspending(updater: suspend (T) -> T): StateUpdateResult<T>

Transforms the state using a suspending function while maintaining thread safety.

Link copied to clipboard
fun <T> StateContainer<T>.withState(action: (T) -> Unit)

Executes an action with the current state.