Cancel the *fut* future or task and wait until it completes.
(fut)
| 535 | |
| 536 | |
| 537 | async def _cancel_and_wait(fut): |
| 538 | """Cancel the *fut* future or task and wait until it completes.""" |
| 539 | |
| 540 | loop = events.get_running_loop() |
| 541 | waiter = loop.create_future() |
| 542 | cb = functools.partial(_release_waiter, waiter) |
| 543 | fut.add_done_callback(cb) |
| 544 | |
| 545 | try: |
| 546 | fut.cancel() |
| 547 | # We cannot wait on *fut* directly to make |
| 548 | # sure _cancel_and_wait itself is reliably cancellable. |
| 549 | await waiter |
| 550 | finally: |
| 551 | fut.remove_done_callback(cb) |
| 552 | |
| 553 | |
| 554 | class _AsCompletedIterator: |
no test coverage detected
searching dependent graphs…