GitHub

TxDeferred

API reference for TxDeferred.

class TxDeferred[A, E = Never]

TxDeferred(ref) is Effect's makeUnsafe; make is the effect, spelled TxDeferred[int, str].make().

Attributes

AttributeTypeDescription
refTxRef[Option[Result[A, E]]]

Functions

__init__

__init__(ref) -> None
ParameterTypeDescription
refTxRef[Option[Result[A, E]]]
def __init__(self, ref: TxRef[Option[Result[A, E]]]) -> None:
    self._ref = ref

make

make() -> Effect[TxDeferred[A, E]]

Returns Effect[TxDeferred[A, E]]

@classmethod
def make(cls) -> Effect[TxDeferred[A, E]]:
    return sync(lambda: cls(TxRef(None)))

wait

wait() -> Effect[A, E]

Wait until completed (Effect's await), then succeed with the value or fail with the error.

Returns Effect[A, E]

def wait(self) -> Effect[A, E]:
    """Wait until completed (Effect's ``await``), then succeed with the
    value or fail with the error."""

    def decide(state: TransactionMeta) -> Effect[A, E, Transaction]:
        current = _tx_ops.value(state, self._ref)
        if current is None:
            return tx_retry
        result = current.value
        return succeed(result.value) if isinstance(result, Ok) else fail(result.error)

    return _tx_ops.decide(decide)

poll

poll() -> Effect[Option[Result[A, E]]]

Some of the result once completed; None before.

Returns Effect[Option[Result[A, E]]]

def poll(self) -> Effect[Option[Result[A, E]]]:
    """``Some`` of the result once completed; ``None`` before."""
    return self._ref.get()

done

done(result) -> Effect[bool]

Complete with result; False if already completed.

ParameterTypeDescription
resultResult[A, E]

Returns Effect[bool]

def done(self, result: Result[A, E]) -> Effect[bool]:
    """Complete with ``result``; ``False`` if already completed."""

    def complete(current: Option[Result[A, E]]) -> tuple[bool, Option[Result[A, E]]]:
        return (False, current) if current is not None else (True, Some(result))

    return self._ref.modify(complete)

succeed

succeed(value) -> Effect[bool]
ParameterTypeDescription
valueA

Returns Effect[bool]

def succeed(self, value: A) -> Effect[bool]:
    return self.done(Ok(value))

fail

fail(error) -> Effect[bool]
ParameterTypeDescription
errorE

Returns Effect[bool]

def fail(self, error: E) -> Effect[bool]:
    return self.done(Err(error))