async/await in Swift

I happen to have a lot of experience writing a Windows application in c#, where the async/await pattern has been a standard feature for years.

I can say from this experience that it's a great way to handle concurrency and I'm really happy that Apple is bringing this to Swift.

I'm often critical of language improvements that end up reproducing things you could already do with a different syntax, but in this case it's definitely worth it.

If you've never used async/await, it may initially look confusing. It looks like all you're doing is blocking your thread from running until another thread completes, but what really happens is that your thread returns at the point where the await keyword appears, and then resumes later when the result is available. So if your thread is the main thread, which is the most common case, using await doesn't block the main thread.

Exactly how the compiler manages to suspend and resume the thread without destroying your local variables, I don't know, but I'm sure they figured out a way that makes sense.

Frank

Exactly how the compiler manages to suspend and resume the thread without destroying your local variables, I don't know

If you’re curious, I highly recommend WWDC 2021 Session 10254 Swift concurrency: Behind the scenes.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

async/await in Swift
 
 
Q