Create `anyio.Event` on async context (#2459)

* Create `anyio.Event` using a blocking portal

* Use cached property

* Ups
This commit is contained in:
Marcelo Trylesinski 2024-02-04 13:50:31 +01:00 committed by GitHub
parent a9af536a07
commit ec417f7f84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import sys
import typing
import warnings
from concurrent.futures import Future
from functools import cached_property
from types import GeneratorType
from urllib.parse import unquote, urljoin
@ -95,7 +96,6 @@ class WebSocketTestSession:
def __enter__(self) -> WebSocketTestSession:
self.exit_stack = contextlib.ExitStack()
self.portal = self.exit_stack.enter_context(self.portal_factory())
self.should_close = anyio.Event()
try:
_: Future[None] = self.portal.start_task_soon(self._run)
@ -109,6 +109,10 @@ class WebSocketTestSession:
self.extra_headers = message.get("headers", None)
return self
@cached_property
def should_close(self) -> anyio.Event:
return anyio.Event()
async def _notify_close(self) -> None:
self.should_close.set()