Skip to content

Commit

Permalink
make lifespan into a dataclass
Browse files Browse the repository at this point in the history
  • Loading branch information
adhami3310 committed Oct 30, 2024
1 parent 948d35f commit ea8b32d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion reflex/app_mixins/lifespan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import asyncio
import contextlib
import dataclasses
import functools
import inspect
from typing import Callable, Coroutine, Set, Union
Expand All @@ -16,11 +17,14 @@
from .mixin import AppMixin


@dataclasses.dataclass
class LifespanMixin(AppMixin):
"""A Mixin that allow tasks to run during the whole app lifespan."""

# Lifespan tasks that are planned to run.
lifespan_tasks: Set[Union[asyncio.Task, Callable]] = set()
lifespan_tasks: Set[Union[asyncio.Task, Callable]] = dataclasses.field(
default_factory=set
)

@contextlib.asynccontextmanager
async def _run_lifespan_tasks(self, app: FastAPI):
Expand Down

0 comments on commit ea8b32d

Please sign in to comment.