Get rid of external teardown trigger because #245 resolves the problem

246_facepalm_backup
overclockworked64 2021-10-22 03:03:41 +02:00 committed by Tyler Goodlet
parent 04895b9d5e
commit 87e3d32992
1 changed files with 3 additions and 8 deletions

View File

@ -17,7 +17,6 @@ async def _enter_and_wait(
mngr: AsyncContextManager[T], mngr: AsyncContextManager[T],
unwrapped: dict[int, T], unwrapped: dict[int, T],
all_entered: trio.Event, all_entered: trio.Event,
teardown_trigger: trio.Event,
) -> None: ) -> None:
'''Open the async context manager deliver it's value '''Open the async context manager deliver it's value
to this task's spawner and sleep until cancelled. to this task's spawner and sleep until cancelled.
@ -29,18 +28,13 @@ async def _enter_and_wait(
if all(unwrapped.values()): if all(unwrapped.values()):
all_entered.set() all_entered.set()
await teardown_trigger.wait() await trio.sleep_forever()
@acm @acm
async def async_enter_all( async def async_enter_all(
mngrs: Sequence[AsyncContextManager[T]], mngrs: Sequence[AsyncContextManager[T]],
teardown_trigger: trio.Event,
) -> AsyncGenerator[tuple[T, ...], None]: ) -> AsyncGenerator[tuple[T, ...], None]:
"""This async context manager expects a 'teardown_trigger' from the
outside world which will be used internally to gracefully teardown
individual context managers.
"""
unwrapped = {}.fromkeys(id(mngr) for mngr in mngrs) unwrapped = {}.fromkeys(id(mngr) for mngr in mngrs)
all_entered = trio.Event() all_entered = trio.Event()
@ -52,10 +46,11 @@ async def async_enter_all(
mngr, mngr,
unwrapped, unwrapped,
all_entered, all_entered,
teardown_trigger,
) )
# deliver control once all managers have started up # deliver control once all managers have started up
await all_entered.wait() await all_entered.wait()
yield tuple(unwrapped.values()) yield tuple(unwrapped.values())
n.cancel_scope.cancel()