dheraingoud's picture
sync: upstream 9194f15 + custom addons (KeyRotator, RotatingChatTransport, sol/terra/luna, ScannerTrap, health, Py3.12 compat)
e99df76
Raw History Blame Contribute Delete
502 Bytes
from __future__ import annotations
"""Drain Copilot-owned work before propagating caller cancellation."""
import asyncio
async def drain_owned[T](task: asyncio.Task[T]) -> T:
cancelled = False
while not task.done():
try:
await asyncio.shield(task)
except asyncio.CancelledError:
if task.cancelled():
raise
cancelled = True
result = task.result()
if cancelled:
raise asyncio.CancelledError
return result