I can't shake the thought that perhaps ideally any @MainActor function should be allowed to have await
keywords directly in its body despite not being itself marked as async
- with the assumption that doing so would simply run the operation on the main actor and suspend the main actor for other actors as-required.
@MainActor
override func viewDidLoad() {
super.viewDidLoad()
self.textField.text = await self.model.name
}
This would make it so much easier to integrate asynchronous functions into existing synchronous paradigms; where there are common requirements that the synchronous function be suspended until data lookups complete in order to populate the view correctly before rendering.
I'd love to learn what, if any, issues exist that prevent us from adding this to the language.