Get rid of external teardown trigger because #245 resolves the problem
parent
04895b9d5e
commit
87e3d32992
|
@ -17,7 +17,6 @@ async def _enter_and_wait(
|
|||
mngr: AsyncContextManager[T],
|
||||
unwrapped: dict[int, T],
|
||||
all_entered: trio.Event,
|
||||
teardown_trigger: trio.Event,
|
||||
) -> None:
|
||||
'''Open the async context manager deliver it's value
|
||||
to this task's spawner and sleep until cancelled.
|
||||
|
@ -29,18 +28,13 @@ async def _enter_and_wait(
|
|||
if all(unwrapped.values()):
|
||||
all_entered.set()
|
||||
|
||||
await teardown_trigger.wait()
|
||||
await trio.sleep_forever()
|
||||
|
||||
|
||||
@acm
|
||||
async def async_enter_all(
|
||||
mngrs: Sequence[AsyncContextManager[T]],
|
||||
teardown_trigger: trio.Event,
|
||||
) -> 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)
|
||||
|
||||
all_entered = trio.Event()
|
||||
|
@ -52,10 +46,11 @@ async def async_enter_all(
|
|||
mngr,
|
||||
unwrapped,
|
||||
all_entered,
|
||||
teardown_trigger,
|
||||
)
|
||||
|
||||
# deliver control once all managers have started up
|
||||
await all_entered.wait()
|
||||
|
||||
yield tuple(unwrapped.values())
|
||||
|
||||
n.cancel_scope.cancel()
|
Loading…
Reference in New Issue