GitHub

API reference for TxRef.

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

AttributeTypeDescription
versionint

How many committed writes changed the value.

Functions

__init__

__init__(value) -> None
ParameterTypeDescription
valueA
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]]
ParameterTypeDescription
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]
ParameterTypeDescription
valueA

Returns Effect[None]

def set(self, value: A) -> Effect[None]:
    return self.modify(lambda _: (None, value))

update

update(f) -> Effect[None]
ParameterTypeDescription
fCallable[[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.

ParameterTypeDescription
fCallable[[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)