(fut, loop)
Cancel the *fut* future or task and wait until it completes.
Cancel the *fut* future or task and wait until it completes.
Cancel the * fut * future or task and wait until it completes .
async def _cancel_and_wait(fut, loop):
    """Cancel the *fut* future or task and wait until it completes."""

    waiter = loop.create_future()
    cb = functools.partial(_release_waiter, waiter)
    fut.add_done_callback(cb)

    try:
        fut.cancel()
        # We cannot wait on *fut* directly to make
        # sure _cancel_and_wait itself is reliably cancellable.
        await waiter
    finally:
        fut.remove_done_callback(cb)
async def _cancel_and_wait ( fut , loop ) : waiter = loop . create_future ( ) cb = functools . partial ( _release_waiter , waiter ) fut . add_done_callback ( cb ) try : fut . cancel ( ) # We cannot wait on *fut* directly to make # sure _cancel_and_wait itself is reliably cancellable. await waiter finally : fut . remove_done_callback ( cb )