In my other topic Returning non-Sendable object across actor boundaries via sending keyword I just learned that I can use async let
in this case as well. Without a return type for the child task, it looks a bit ugly though:
@MainActor func main() {
print(Thread.isMainThread)
Task {
async let _ = a()
}
}
And if I wanted to await the child task before proceeding, I could write
async let a = a()
await a
with a compiler warning
Constant 'a' inferred to have type '()', which may be unexpected
If someone has a better solution, you're welcome to share it!