async def create_temp_file(
    extension: str, content: bytes | None = None
) -> tuple[Path, Callable[[], Coroutine[None, None, None]]]:
    """Create a temporary file that is closed.

    Args:
        extension: The file extension.
        content: The content to write to the file.

    Returns:
        The temporary file path.
    """
    file = await run_sync(NamedTemporaryFile, suffix=extension, delete=False)
    if content:
        await AsyncPath(file.name).write_bytes(content)
    await run_sync(file.close)

    async def unlink() -> None:
        with suppress(OSError, PermissionError):
            await AsyncPath(file.name).unlink(missing_ok=True)

    return Path(file.name), unlink
Create a temporary file that is closed.

    Args:
        extension: The file extension.
        content: The content to write to the file.

    Returns:
        The temporary file path.
    
kreuzberg/_utils/_tmp.py