|
16 | 16 | from ._exceptions import ChannelClosedError |
17 | 17 | from ._generic import ChannelMessageT |
18 | 18 | from ._receiver import Receiver, ReceiverStoppedError |
19 | | -from ._sender import Sender, SenderError |
| 19 | +from ._sender import ClonableSubscribableSender, SenderError |
20 | 20 |
|
21 | 21 | _logger = logging.getLogger(__name__) |
22 | 22 |
|
@@ -269,7 +269,7 @@ async def close(self) -> None: # noqa: D402 |
269 | 269 | """Close the channel, deprecated alias for `aclose()`.""" # noqa: D402 |
270 | 270 | return await self.aclose() |
271 | 271 |
|
272 | | - def new_sender(self) -> Sender[ChannelMessageT]: |
| 272 | + def new_sender(self) -> ClonableSubscribableSender[ChannelMessageT]: |
273 | 273 | """Return a new sender attached to this channel.""" |
274 | 274 | return _Sender(self) |
275 | 275 |
|
@@ -317,7 +317,7 @@ def __repr__(self) -> str: |
317 | 317 | _T = TypeVar("_T") |
318 | 318 |
|
319 | 319 |
|
320 | | -class _Sender(Sender[_T]): |
| 320 | +class _Sender(ClonableSubscribableSender[_T]): |
321 | 321 | """A sender to send messages to the broadcast channel. |
322 | 322 |
|
323 | 323 | Should not be created directly, but through the |
@@ -365,6 +365,16 @@ async def send(self, message: _T, /) -> None: |
365 | 365 | self._channel._recv_cv.notify_all() |
366 | 366 | # pylint: enable=protected-access |
367 | 367 |
|
| 368 | + @override |
| 369 | + def clone(self) -> _Sender[_T]: |
| 370 | + """Return a clone of this sender.""" |
| 371 | + return _Sender(self._channel) |
| 372 | + |
| 373 | + @override |
| 374 | + def subscribe(self) -> Receiver[_T]: |
| 375 | + """Return a new receiver attached to this sender's channel.""" |
| 376 | + return self._channel.new_receiver() |
| 377 | + |
368 | 378 | def __str__(self) -> str: |
369 | 379 | """Return a string representation of this sender.""" |
370 | 380 | return f"{self._channel}:{type(self).__name__}" |
|
0 commit comments