MCPcopy
hub / github.com/encode/httpx / BoundAsyncStream

Class BoundAsyncStream

httpx/_client.py:162–182  ·  view source on GitHub ↗

An async byte stream that is bound to a given response instance, and that ensures the `response.elapsed` is set once the response is closed.

Source from the content-addressed store, hash-verified

160
161
162class BoundAsyncStream(AsyncByteStream):
163 """
164 An async byte stream that is bound to a given response instance, and that
165 ensures the `response.elapsed` is set once the response is closed.
166 """
167
168 def __init__(
169 self, stream: AsyncByteStream, response: Response, start: float
170 ) -> None:
171 self._stream = stream
172 self._response = response
173 self._start = start
174
175 async def __aiter__(self) -> typing.AsyncIterator[bytes]:
176 async for chunk in self._stream:
177 yield chunk
178
179 async def aclose(self) -> None:
180 elapsed = time.perf_counter() - self._start
181 self._response.elapsed = datetime.timedelta(seconds=elapsed)
182 await self._stream.aclose()
183
184
185EventHook = typing.Callable[..., typing.Any]

Callers 1

_send_single_requestMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected