Allow App.startup()
to be async
#2857
Labels
enhancement
New features, or improvements to existing features.
App.startup()
to be async
#2857
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 #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 theirstartup()
method as async.I imagine to accomplish this, the current
App._startup()
method would need to be broken up. The invocation ofApp.startup()
would be viaasyncio.create_task(handler(self.startup))
; then the remaining logic inApp._startup()
would be refactored in to a new method that is added as a callback for the Task forApp.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 becausemain_window
isn't set which is likely to be confusing to users.Additional context
No response
The text was updated successfully, but these errors were encountered: