Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp modules structure #235

Merged
merged 13 commits into from
Nov 9, 2023
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ body:
- Documentation (part:docs)
- Unit, integration and performance tests (part:tests)
- Build script, CI, dependencies, etc. (part:tooling)
- Channels, `Broadcast`, `Bidirectional`, etc. (part:channels)
- Channels, `Broadcast`, `Anycast`, etc. (part:channels)
- Select (part:select)
- Utility receivers, `Merge`, etc. (part:receivers)
validations:
Expand Down
17 changes: 1 addition & 16 deletions src/frequenz/channels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@
senders and multiple receivers. A message sent through a sender will be
received by exactly one receiver.

* [Bidirectional][frequenz.channels.Bidirectional]: A channel providing
a `client` and a `service` handle to send and receive bidirectionally.

* [Broadcast][frequenz.channels.Broadcast]: A channel to broadcast messages
from multiple senders to multiple receivers. Each message sent through any of
the senders is received by all of the receivers.

Other base classes:

* [Peekable][frequenz.channels.Peekable]: An object to allow users to get
a peek at the latest value in the channel, without consuming anything.

* [Receiver][frequenz.channels.Receiver]: An object that can wait for and
consume messages from a channel.

Expand Down Expand Up @@ -55,38 +49,29 @@

* [ReceiverStoppedError][frequenz.channels.ReceiverStoppedError]: A receiver
stopped producing messages.

* [ReceiverInvalidatedError][frequenz.channels.ReceiverInvalidatedError]:
A receiver is not longer valid (for example if it was converted into
a peekable.
"""

from . import util
from ._anycast import Anycast
from ._base_classes import Peekable, Receiver, Sender
from ._bidirectional import Bidirectional
from ._base_classes import Receiver, Sender
from ._broadcast import Broadcast
from ._exceptions import (
ChannelClosedError,
ChannelError,
Error,
ReceiverError,
ReceiverInvalidatedError,
ReceiverStoppedError,
SenderError,
)

__all__ = [
"Anycast",
"Bidirectional",
"Broadcast",
"ChannelClosedError",
"ChannelError",
"Error",
"Peekable",
"Receiver",
"ReceiverError",
"ReceiverInvalidatedError",
"ReceiverStoppedError",
"Sender",
"SenderError",
Expand Down
34 changes: 0 additions & 34 deletions src/frequenz/channels/_base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,40 +122,6 @@ def map(self, call: Callable[[T], U]) -> Receiver[U]:
"""
return _Map(self, call)

def into_peekable(self) -> Peekable[T]:
"""Convert the `Receiver` implementation into a `Peekable`.

Once this function has been called, the receiver will no longer be
usable, and calling `receive` on the receiver will raise an exception.

Returns:
A `Peekable` that can be used to peek at the latest value in the
channel.

Raises:
NotImplementedError: when a `Receiver` implementation doesn't have
a custom `into_peekable` implementation.
"""
raise NotImplementedError("This receiver does not implement `into_peekable`")


class Peekable(ABC, Generic[T]):
"""A channel peekable.

A Peekable provides a [peek()][frequenz.channels.Peekable] method that
allows the user to get a peek at the latest value in the channel, without
consuming anything.
"""

@abstractmethod
def peek(self) -> T | None:
"""Return the latest value that was sent to the channel.

Returns:
The latest value received by the channel, and `None`, if nothing
has been sent to the channel yet.
"""


class _Map(Receiver[U], Generic[T, U]):
"""Apply a transform function on a channel receiver.
Expand Down
206 changes: 0 additions & 206 deletions src/frequenz/channels/_bidirectional.py

This file was deleted.

Loading