|
4 | 4 | from collections.abc import Callable
|
5 | 5 | from typing import Any, Generic, TypeVar, Union
|
6 | 6 |
|
7 |
| -from .._core._exceptions import EndOfStream |
| 7 | +from .._core._exceptions import EndOfStream, WouldBlock |
8 | 8 | from .._core._typedattr import TypedAttributeProvider
|
9 | 9 | from ._resources import AsyncResource
|
10 | 10 | from ._tasks import TaskGroup
|
@@ -36,6 +36,20 @@ async def __anext__(self) -> T_co:
|
36 | 36 | except EndOfStream:
|
37 | 37 | raise StopAsyncIteration
|
38 | 38 |
|
| 39 | + def receive_nowait(self) -> T_co: |
| 40 | + """ |
| 41 | + Receive the next item if it can be done without waiting. |
| 42 | +
|
| 43 | + :raises ~anyio.ClosedResourceError: if the receive stream has been explicitly |
| 44 | + closed |
| 45 | + :raises ~anyio.EndOfStream: if this stream has been closed from the other end |
| 46 | + :raises ~anyio.BrokenResourceError: if this stream has been rendered unusable |
| 47 | + due to external causes |
| 48 | + :raises ~anyio.WouldBlock: if there is no item immeditately available |
| 49 | +
|
| 50 | + """ |
| 51 | + raise WouldBlock |
| 52 | + |
39 | 53 | @abstractmethod
|
40 | 54 | async def receive(self) -> T_co:
|
41 | 55 | """
|
@@ -132,6 +146,21 @@ async def __anext__(self) -> bytes:
|
132 | 146 | except EndOfStream:
|
133 | 147 | raise StopAsyncIteration
|
134 | 148 |
|
| 149 | + def receive_nowait(self, max_bytes: int = 65536) -> bytes: |
| 150 | + """ |
| 151 | + Receive at most ``max_bytes`` bytes from the peer, if it can be done without |
| 152 | + blocking. |
| 153 | +
|
| 154 | + .. note:: Implementors of this interface should not return an empty |
| 155 | + :class:`bytes` object, and users should ignore them. |
| 156 | +
|
| 157 | + :param max_bytes: maximum number of bytes to receive |
| 158 | + :return: the received bytes |
| 159 | + :raises ~anyio.EndOfStream: if this stream has been closed from the other end |
| 160 | + :raises ~anyio.WouldBlock: if there is no data waiting to be received |
| 161 | + """ |
| 162 | + raise WouldBlock |
| 163 | + |
135 | 164 | @abstractmethod
|
136 | 165 | async def receive(self, max_bytes: int = 65536) -> bytes:
|
137 | 166 | """
|
|
0 commit comments