def register_lifespan_task(self, task: Callable | asyncio.Task, **task_kwargs):
        """Register a task to run during the lifespan of the app.

        Args:
            task: The task to register.
            **task_kwargs: The kwargs of the task.

        Raises:
            InvalidLifespanTaskTypeError: If the task is a generator function.
        """
        if inspect.isgeneratorfunction(task) or inspect.isasyncgenfunction(task):
            msg = f"Task {task.__name__} of type generator must be decorated with contextlib.asynccontextmanager."
            raise InvalidLifespanTaskTypeError(msg)

        if task_kwargs:
            original_task = task
            task = functools.partial(task, **task_kwargs)  # pyright: ignore [reportArgumentType]
            functools.update_wrapper(task, original_task)  # pyright: ignore [reportArgumentType]
        self.lifespan_tasks.add(task)
        console.debug(f"Registered lifespan task: {task.__name__}")  # pyright: ignore [reportAttributeAccessIssue]
Register a task to run during the lifespan of the app.

        Args:
            task: The task to register.
            **task_kwargs: The kwargs of the task.

        Raises:
            InvalidLifespanTaskTypeError: If the task is a generator function.
        
reflex/app_mixins/lifespan.py