Cancel the *fut* future or task and wait until it completes.
(fut: asyncio.Future[_T])
| 73 | |
| 74 | |
| 75 | async def _cancel_and_wait(fut: asyncio.Future[_T]) -> None: |
| 76 | """Cancel the *fut* future or task and wait until it completes.""" |
| 77 | |
| 78 | loop = asyncio.get_running_loop() |
| 79 | waiter = loop.create_future() |
| 80 | cb = functools.partial(_release_waiter, waiter) |
| 81 | fut.add_done_callback(cb) |
| 82 | |
| 83 | try: |
| 84 | fut.cancel() |
| 85 | # We cannot wait on *fut* directly to make |
| 86 | # sure _cancel_and_wait itself is reliably cancellable. |
| 87 | await waiter |
| 88 | finally: |
| 89 | fut.remove_done_callback(cb) |
| 90 | |
| 91 | |
| 92 | def _release_waiter(waiter: asyncio.Future[typing.Any], *args: object) -> None: |
no outgoing calls
no test coverage detected
searching dependent graphs…