SequentialActor

class SequentialActor<Context, S>(initial: S, scope: CoroutineScope = CoroutineScope(Dispatchers.IO)) : StateActor<Context, S> (source)

A StateActor that serializes all action execution via a FIFO Channel.

Actions dispatched with effect or immediate execute in dispatch order and never run concurrently — matching the behavior of a single-threaded queue dispatcher.

Re-entrant: actions that call immediate on the same actor execute inline (they're already inside the consumer loop).

Constructors

Link copied to clipboard
constructor(initial: S, scope: CoroutineScope = CoroutineScope(Dispatchers.IO))

Properties

Link copied to clipboard
open override val state: StateFlow<S>

Functions

Link copied to clipboard
fun close()

Closes the queue. The consumer loop exits after draining remaining items.

Link copied to clipboard
open override fun <Ctx> effect(ctx: Ctx, action: TypedAction<Ctx>)

Fire-and-forget: enqueue action in FIFO order, return immediately.

Link copied to clipboard
open suspend override fun <Ctx> immediate(ctx: Ctx, action: TypedAction<Ctx>)

Dispatch action inline and suspend until it completes. Goes through action interceptors. Use for cross-slice coordination where the caller needs to await the action finishing.

Link copied to clipboard
open suspend override fun <Ctx> immediateUntil(ctx: Ctx, action: TypedAction<Ctx>, until: (S) -> Boolean): S

Dispatch action and suspend until state matches until.

Link copied to clipboard
fun onAction(interceptor: (action: Any, next: () -> Unit) -> Unit)

Add an action interceptor. Call next() to proceed, or skip to suppress the action. Action is Any — cast to inspect.

Link copied to clipboard
fun onActionExecution(interceptor: suspend (action: Any, next: suspend () -> Unit) -> Unit)

Add an async interceptor that wraps the action's suspend execution. Runs inside the coroutine — next() suspends until the action completes.

Link copied to clipboard
fun onUpdate(interceptor: (reducer: Reducer<S>, next: (Reducer<S>) -> Unit) -> Unit)

Add an update interceptor. Call next(reducer) to proceed, or skip to suppress the update.

Link copied to clipboard
open override fun update(reducer: Reducer<S>)

Atomic state mutation using CAS retry, routed through update interceptors.