It may be the case that while yeah the methods are async they do create an Unstructured Task anyway which isn’t great but would explain what you’re seeing perhaps?
I mean you say “returns before completes” but just adding prints to this snippet are you actually sure that’s what’s happening, and not some effects of the funcs being from some unstructured task?
Sorry but it’s hard to think of anything else, perhaps if you could provide a reproducer we could dig more into it.
I got it, it's my fault, there is a condition check in the updateUserInfo method to prevent multiple calls, and the updateUserInfo method is called from another method, the code should be like this:
let vm = MyStatusViewModel.shared
vm.switchStatus()
try await updateUserInfo()
It looks like functionA isn't truly waiting for functionB to finish before continuing. Are you sure ClassB.doSomething() and ClassC.doSomething() are properly marked as async and awaited? Also, check if they are running tasks on a detached thread, which might be causing the unexpected behavior. Try using await Task.sleep(...) for debugging to see execution order more clearly.