API reference › @evolu/common › Task › MutexRef
Defined in: packages/common/src/Task.ts:6149
MutexRef serializes reads, writes, and updates through an internal Mutex.
Reads see a stable value, while writes and updates commit one transition at a
time. When an update fails or is aborted, the previous value is preserved.
MutexRef is non-reentrant. Updaters and modifiers run while holding the
internal Mutex, so calling another method on the same MutexRef from inside
one of them waits on itself and will not progress.
Use it for state whose transitions are Tasks: atomic async read-modify-write. Plain Ref cannot express that — between a sync read and a later write, a concurrent transition can interleave and get lost.
MutexRef reads, writes, and updates are Tasks and incur normal Run
lifecycle overhead. Use Ref instead for synchronous state transitions,
especially on allocation-sensitive hot paths.
See
Properties
get
readonly get: Task<T>;
Defined in: packages/common/src/Task.ts:6151
Returns the current value.
getAndSet
readonly getAndSet: (value: T) => Task<T>;
Defined in: packages/common/src/Task.ts:6157
Sets the current value and returns the previous value.
getAndUpdate
readonly getAndUpdate: <E, D>(updater: (current: T) => Task<T, E, D>) => Task<T, E, D>;
Defined in: packages/common/src/Task.ts:6168
Updates the current value and returns the previous value.
modify
readonly modify: <R, E, D>(modifier: (current: T) => Task<readonly [R, T], E, D>) => Task<R, E, D>;
Defined in: packages/common/src/Task.ts:6178
Modifies the current value and returns a computed result.
set
readonly set: (value: T) => Task<void>;
Defined in: packages/common/src/Task.ts:6154
Sets the current value.
setAndGet
readonly setAndGet: (value: T) => Task<T>;
Defined in: packages/common/src/Task.ts:6160
Sets the current value and returns it.
snapshot
readonly snapshot: () => SemaphoreSnapshot;
Defined in: packages/common/src/Task.ts:6183
Returns the current lock state for monitoring and debugging.
update
readonly update: <E, D>(updater: (current: T) => Task<T, E, D>) => Task<void, E, D>;
Defined in: packages/common/src/Task.ts:6163
Updates the current value.
updateAndGet
readonly updateAndGet: <E, D>(updater: (current: T) => Task<T, E, D>) => Task<T, E, D>;
Defined in: packages/common/src/Task.ts:6173
Updates the current value and returns it.