Allow `App.startup()` to be async
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 827
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 40
Description
### What is the problem or limitation you are having?
An app's `startup()` method cannot be defined as async. Therefore, to take async actions at startup, users must factor out the async logic to run from the event loop.
### Describe the solution you'd like
With the resolution of https://github.com/beeware/toga/issues/2834, Toga now ensures that the event loop is running on all platforms when `startup()` is invoked. Given this, the entire startup process can now support being async. Specifically, users would be able to define their `startup()` method as async.
I imagine to accomplish this, the current `App._startup()` method would need to be broken up. The invocation of `App.startup()` would be via `asyncio.create_task(handler(self.startup))`; then the remaining logic in `App._startup()` would be refactored in to a new method that is added as a callback for the Task for `App.startup()`.
### Describe alternatives you've considered
Users can factor out the async logic in to either `on_running()` or their own custom task.
If this idea is rejected, then Toga should error if `startup()` is async; currently, it errors because` main_window` isn't set which is likely to be confusing to users.
### Additional context
_No response_
Contributor guide
Research direction
Start with App._startup and the event-loop changes from issue #2834; compare how App.startup and on_running are invoked. Trace the startup task lifecycle across supported platforms, then add coverage for async startup and confirm that the remaining startup initialization occurs after it completes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- desktop
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100