mirror of https://github.com/encode/starlette.git
Create `anyio.Event` on async context (#2459)
* Create `anyio.Event` using a blocking portal * Use cached property * Ups
This commit is contained in:
parent
a9af536a07
commit
ec417f7f84
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue