import asyncio


def maybe_set_exception(fut: asyncio.Future, exc: BaseException) -> bool:
    """Set future exception if not already done."""
    if fut is not None and not fut.done():
        fut.set_exception(exc)
        return True
    return False