qasync icon indicating copy to clipboard operation
qasync copied to clipboard

How to use asyncClose?

Open jamesdbrock opened this issue 1 year ago • 1 comments

I'm trying to understand how to use asyncClose.

https://github.com/CabbageDevelopment/qasync/blob/a6eb8e55a112e1c115fd1ed4cd8f120abb097a55/examples/aiohttp_fetch.py#L45-L47

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 avatar Feb 08 '24 06:02 jamesdbrock

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?

jamesdbrock avatar Feb 08 '24 09:02 jamesdbrock