Skip to content

Commit

Permalink
❇️ Add awaitable close method within AsyncSession (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ousret authored Jan 18, 2024
1 parent 5763718 commit 4f19090
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Release History
**Fixed**
- Issuing a request with `Session(multiplexed=True)` that weren't eligible (e.g. HTTP/1.1) but was redirected to an
eligible server (HTTP/2+) caused a rare error.
- An anonymous netrc entry (e.g. username only) could be wrongfully used when it should be discarded. (PR #61)

**Added**
- Awaitable close method within `AsyncSession`.

3.4.3 (2024-01-16)
------------------
Expand Down
4 changes: 2 additions & 2 deletions src/niquests/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
__url__: str = "https://niquests.readthedocs.io"

__version__: str
__version__ = "3.4.3"
__version__ = "3.4.4"

__build__: int = 0x030403
__build__: int = 0x030404
__author__: str = "Kenneth Reitz"
__author_email__: str = "me@kennethreitz.org"
__license__: str = "Apache-2.0"
Expand Down
10 changes: 7 additions & 3 deletions src/niquests/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ async def __aenter__(self):
return self

async def __aexit__(self, exc, value, tb):
await sync_to_async(
super().__exit__, thread_sensitive=AsyncSession.disable_thread
)()
await self.close()

async def send( # type: ignore[override]
self, request: PreparedRequest, **kwargs: typing.Any
Expand Down Expand Up @@ -718,6 +716,12 @@ async def gather(self, *responses: Response, max_fetch: int | None = None) -> No
thread_sensitive=AsyncSession.disable_thread,
)(*responses, max_fetch=max_fetch)

async def close(self) -> None: # type: ignore[override]
await sync_to_async(
super().close,
thread_sensitive=AsyncSession.disable_thread,
)()


class AsyncResponse(Response):
def __aenter__(self) -> AsyncResponse:
Expand Down

0 comments on commit 4f19090

Please sign in to comment.