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

How to use asyncClose? #112

Open
jamesdbrock opened this issue Feb 8, 2024 · 1 comment
Open

How to use asyncClose? #112

jamesdbrock opened this issue Feb 8, 2024 · 1 comment

Comments

@jamesdbrock
Copy link

I'm trying to understand how to use asyncClose.

@asyncClose
async def closeEvent(self, event): # noqa:N802
await self.session.close()

How does this example work? closeEvent is not referenced from anywhere. It's the same on the README example.

What I want: I have an app with some async tasks running. When the user closes the app, I want to app to cancel() all of the async tasks and then exit after all of the cancellations are done().

@jamesdbrock
Copy link
Author

When the user closes the app, I want to app to cancel() all of the async tasks and then exit after all of the cancellations are done().

I figured out how to do with without asyncClose. It looks like this:

        self._app_close_event = asyncio.Event()

        async def app_run():
            await self._app_close_event.wait()
            self._render_engine._delete_component(self._root, True)
            # At this time, all use_async hook tasks have been cancel()ed.
            # Wait until all the cancelled tasks are done(), then exit.
            while len(self._render_engine._hook_async) > 0:
                await asyncio.sleep(0.0)

        loop.run_until_complete(app_run())

I'm still curious what the use-case is for asyncClose?

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

1 participant