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

support async callback with state #2295

Merged
merged 4 commits into from
Dec 2, 2024

Conversation

FredLL-Avaiga
Copy link
Member

@FredLL-Avaiga FredLL-Avaiga commented Nov 29, 2024

resolves #2288

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Support async callback
inspired by
@FlorianJacta proposal

Related Tickets & Documents

How to reproduce the issue

import asyncio

import taipy.gui.builder as tgb
from taipy.gui import Gui, State


async def heavy_function(state: State):
    state.logs = "Starting...\n"
    state.logs += "Searching documents\n"
    await asyncio.sleep(5)
    state.logs += "Responding to user\n"
    await asyncio.sleep(5)
    state.logs += "Fact Checking\n"
    await asyncio.sleep(5)
    state.result = "Done!"


if __name__ == "__main__":
    logs = ""
    result = "No response yet"

    with tgb.Page() as main_page:
        tgb.button("Respond", on_action=heavy_function)
        with tgb.part("card"):
            tgb.text("{logs}", mode="pre")

        tgb.text("# Result", mode="md")
        tgb.text("{result}")

    gui = Gui(main_page)
    gui.run(title="2288 aync callback")

@FredLL-Avaiga FredLL-Avaiga added 🟨 Priority: Medium Not blocking but should be addressed 📝Release Notes Impacts the Release Notes or the Documentation in general Gui: Back-End labels Nov 29, 2024
@FredLL-Avaiga FredLL-Avaiga self-assigned this Nov 29, 2024
Copy link
Member

@FabienLelaquais FabienLelaquais left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮amazingly neat!!
We need a code example for this one.
An async function that would do something relevant (like searching whether a large number is prime or not) to demonstrate the feature.
Great, great job!

ADDITION: I just spotted the code example you provide.
I'm not sure we can keep it as is, but maybe it's just what we want.
Then it should go to taipy/doc/gui/examples. async_callback.py?

@FredLL-Avaiga
Copy link
Member Author

Would be nice to have a neat example...

add a simple example
Copy link
Member

@dinhlongviolin1 dinhlongviolin1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very very nice!

Copy link
Contributor

github-actions bot commented Nov 29, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
19424 16903 87% 0% 🟢

New Files

File Coverage Status
taipy/gui/utils/threads.py 63% 🟢
TOTAL 63% 🟢

Modified Files

File Coverage Status
taipy/gui/gui.py 80% 🟢
taipy/gui/gui_actions.py 66% 🟢
taipy/gui/state.py 84% 🟢
TOTAL 77% 🟢

updated for commit: df3edde by action🐍

Copy link
Member

@FabienLelaquais FabienLelaquais left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌👌👌

@FredLL-Avaiga FredLL-Avaiga merged commit 6911157 into develop Dec 2, 2024
126 checks passed
@FredLL-Avaiga FredLL-Avaiga deleted the feature/#2288-async-callback branch December 2, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gui: Back-End 🟨 Priority: Medium Not blocking but should be addressed 📝Release Notes Impacts the Release Notes or the Documentation in general
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify asynchronous/long running callbacks
3 participants