MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / _cancel_and_wait

Function _cancel_and_wait

asyncpg/_asyncio_compat.py:75–89  ·  view source on GitHub ↗

Cancel the *fut* future or task and wait until it completes.

(fut: asyncio.Future[_T])

Source from the content-addressed store, hash-verified

73
74
75async 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
92def _release_waiter(waiter: asyncio.Future[typing.Any], *args: object) -> None:

Callers 1

wait_forFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…