class TxRef[A = Unsubscripted]
TxRef(value) is Effect's makeUnsafe; TxRef.make is the
effect. A committed write that changes the value (by JavaScript's
Object.is: -0.0 replaces 0.0) bumps version; every
committed write, changed or not, wakes the transactions waiting in
tx_retry on this ref.
Attributes#
| Attribute | Type | Description |
|---|---|---|
version | int | How many committed writes changed the value. |
Functions#
__init__#
__init__(value) -> None| Parameter | Type | Description |
|---|---|---|
value | A |
def __init__(self, value: A) -> None:
self._value = value
self._version = 0
# Wake callbacks of transactions parked in ``tx_retry`` after reading
# this ref, keyed by waiter.
self._pending: dict[object, Callable[[], None]] = {}make#
make[T](value: T) -> Effect[TxRef[T]]
make(value: A) -> Effect[TxRef[A]]| Parameter | Type | Description |
|---|---|---|
value |
@overload
@classmethod
def make[T](cls: type[TxRef[Unsubscripted]], value: T) -> Effect[TxRef[T]]: ...
@overload
@classmethod
def make(cls, value: A) -> Effect[TxRef[A]]: ...
@classmethod
def make[T](cls, value: T) -> Effect[TxRef[T]]:
return _Sync(lambda: TxRef(value))get#
get() -> Effect[A]Returns Effect[A]
def get(self) -> Effect[A]:
return transactional(self._get)set#
set(value) -> Effect[None]| Parameter | Type | Description |
|---|---|---|
value | A |
Returns Effect[None]
def set(self, value: A) -> Effect[None]:
return self.modify(lambda _: (None, value))update#
update(f) -> Effect[None]| Parameter | Type | Description |
|---|---|---|
f | Callable[[A], A] |
Returns Effect[None]
def update(self, f: Callable[[A], A]) -> Effect[None]:
return self.modify(lambda current: (None, f(current)))modify#
modify[B](f) -> Effect[B]Replace the value with the second item of f(value); succeed
with the first.
| Parameter | Type | Description |
|---|---|---|
f | Callable[[A], tuple[B, A]] |
Returns Effect[B]
def modify[B](self, f: Callable[[A], tuple[B, A]]) -> Effect[B]:
"""Replace the value with the second item of ``f(value)``; succeed
with the first."""
def run(state: TransactionMeta) -> B:
entry = state._entry(self)
result, entry._value = f(entry._value)
entry._written = True
return result
return transactional(run)