Concurrency Games: async/await in Swift 5.5

Rahul Goel
2 min readOct 12, 2021

For this article context term concurrency refer to the common combination of asynchronous and parallel code.

“ — :— ”

Parallel code means multiple pieces of code run simultaneously — for example, a computer with a four-core processor can run four pieces of code at the same time, with each core carrying out one of the tasks.

Concurrency = async + parallel Code (not time sharing) for this article

Async Functions:

Async Functions

Sync function can not call async function directly, Async functions can call sync or async funtions both.

Calling Asynchronous Functions in Parallel:

Calling an asynchronous function with await runs only one piece of code at a time. While the asynchronous code is running, the caller waits for that code to finish before moving on to run the next line of code.

To call an asynchronous function and let it run in parallel with code around it, use async let

“async let”

Output :

Output

P.S. : Upto XCode 13.0 this features is available iOS 15.0 and above.

Follow me Rahul Goel for more updates.

--

--

Rahul Goel

Computer Science Enthusiast | 11+ Year of Software Evolution | @Sharechat, Groupon, Paytm, Myntra https://www.linkedin.com/in/therahulgoel/