Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use_task example #987

Open
edan-bainglass opened this issue Jan 27, 2025 · 1 comment
Open

use_task example #987

edan-bainglass opened this issue Jan 27, 2025 · 1 comment

Comments

@edan-bainglass
Copy link

In your async task example

import asyncio
import solara
from solara.lab import use_task, Task


@solara.component
def Page():
    number = solara.use_reactive(4)

    async def square():
        await asyncio.sleep(1)
        return number.value**2

    result: Task[int] = use_task(square, dependencies=[number.value])

    solara.InputInt("Square", value=number, continuous_update=True)
    if result.finished:
        solara.Success(f"Square of {number} == {result.value}")
    solara.ProgressLinear(result.pending)

you annotate the Task with int as the return type of use_task. I think this may no longer be accurate. My editor (VS Code) suggets the return type of use_task is Task[(), Coroutine[Any, Any, int]], thus not allowing me to properly type it.

@iisakkirotko
Copy link
Collaborator

iisakkirotko commented Jan 27, 2025

Could you open an issue on this? Clearly I needed more sleep, for some reason I was convinced this was in a discussion post. Sorry.

I suspect this has never been correct, and should have always been typed as

    result: Task[[], int] = use_task(square, dependencies=[number.value])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants