Skip to content

App.register_lifespan_task should work as a decorator #6330

@masenf

Description

@masenf

Describe the Enhancement you want
register_lifespan_task doesn't return the argument it gets, so if used as a decorator, the decorated task function name gets bound to None and thus cannot be called directly by other parts of the code.

  • What is the benefit of the enhancement?

Cleaner code, more predictable behavior, more convenient.

  • Show an example/usecase were the improvement are needed.
app = rx.App()

@app.register_lifespan_task
def polling_task(app: Starlette):
    ...

@app.register_lifespan_task(timeout=10)
def check_for_updates(timeout: int):
    ...

For the second construction to work, the register_lifespan_task needs to act more like a decorator and have an internal wrapper function which can be returned directly as a partial if the user provides other args besides the function itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAnything you want improved

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions