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 creating background tasks from awaitables #3579

Merged
merged 1 commit into from
Aug 23, 2024
Merged

Support creating background tasks from awaitables #3579

merged 1 commit into from
Aug 23, 2024

Conversation

falkoschindler
Copy link
Contributor

In zauberzeug/rosys#178 we noticed that background_tasks.create doesn't accept awaitables as promised by the type annotation:

class MyAwaitable:
    def __await__(self):
        yield
        print('Awaiting...')

my_awaitable = MyAwaitable()

ui.button('Run', on_click=lambda: background_tasks.create(my_awaitable))

This PR replaces the assertion asyncio.iscoroutine(coroutine) and applies asyncio.wait_for as a wrapper if needed.

@falkoschindler falkoschindler added the bug Something isn't working label Aug 23, 2024
@falkoschindler falkoschindler added this to the 1.4.37 milestone Aug 23, 2024
@rodja rodja merged commit 93efc0c into main Aug 23, 2024
7 checks passed
@rodja rodja deleted the awaitable branch August 23, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants