Skip to content

Observer class

Bases: ABC, Generic[_InT]

A base class that defines the workflow and essential protocols for responding to notifications from an observable.

Notes:

  • This class is parameterized by the type of value that will be received in the next method.
Source code in pyventus/reactive/observers/observer.py
class Observer(ABC, Generic[_InT]):
    """
    A base class that defines the workflow and essential protocols for responding to notifications from an observable.

    **Notes:**

    -   This class is parameterized by the type of value that will be received in the `next` method.

    """

    # Allow subclasses to define __slots__
    __slots__ = ()

    @abstractmethod
    async def next(self, value: _InT) -> None:
        """
        Handle the next value emitted by the observable.

        :param value: The value emitted by the observable.
        :return: None.
        """
        pass

    @abstractmethod
    async def error(self, exception: Exception) -> None:
        """
        Handle an error that occurs in the observable.

        :param exception: The exception that was raised by the observable.
        :return: None.
        """
        pass

    @abstractmethod
    async def complete(self) -> None:
        """
        Handle the completion of the observable.

        :return: None.
        """
        pass

Functions

next abstractmethod async

next(value: _InT) -> None

Handle the next value emitted by the observable.

PARAMETER DESCRIPTION
value

The value emitted by the observable.

TYPE: _InT

RETURNS DESCRIPTION
None

None.

Source code in pyventus/reactive/observers/observer.py
@abstractmethod
async def next(self, value: _InT) -> None:
    """
    Handle the next value emitted by the observable.

    :param value: The value emitted by the observable.
    :return: None.
    """
    pass

error abstractmethod async

error(exception: Exception) -> None

Handle an error that occurs in the observable.

PARAMETER DESCRIPTION
exception

The exception that was raised by the observable.

TYPE: Exception

RETURNS DESCRIPTION
None

None.

Source code in pyventus/reactive/observers/observer.py
@abstractmethod
async def error(self, exception: Exception) -> None:
    """
    Handle an error that occurs in the observable.

    :param exception: The exception that was raised by the observable.
    :return: None.
    """
    pass

complete abstractmethod async

complete() -> None

Handle the completion of the observable.

RETURNS DESCRIPTION
None

None.

Source code in pyventus/reactive/observers/observer.py
@abstractmethod
async def complete(self) -> None:
    """
    Handle the completion of the observable.

    :return: None.
    """
    pass