def METHOD_NAME(self) -> None:
    """Cancel a task if connection was lost and the task should be cancelled if no connection is established."""
    if self.restart_after_reconnect and self._task:
        logger.debug("Stopping task %s because of connection loss.", self.name)
        self.cancel()