Cancel the *fut* future or task and wait until it completes.
(fut, loop)
| 549 | |
| 550 | |
| 551 | async def _cancel_and_wait(fut, loop): |
| 552 | """Cancel the *fut* future or task and wait until it completes.""" |
| 553 | |
| 554 | waiter = loop.create_future() |
| 555 | cb = functools.partial(_release_waiter, waiter) |
| 556 | fut.add_done_callback(cb) |
| 557 | |
| 558 | try: |
| 559 | fut.cancel() |
| 560 | # We cannot wait on *fut* directly to make |
| 561 | # sure _cancel_and_wait itself is reliably cancellable. |
| 562 | await waiter |
| 563 | finally: |
| 564 | fut.remove_done_callback(cb) |
| 565 | |
| 566 | |
| 567 | # This is *not* a @coroutine! It is just an iterator (yielding Futures). |
no test coverage detected