Modern Concurrency: Getting Started

Oct 18 2022 · Swift 5.5, iOS 15, Xcode 13.4

Part 2: Asynchronous Sequences

10. Concurrency With async let

Episode complete

Play next episode

About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 09. Your Second Asynchronous App Next episode: 11. Using Asynchronous Methods in Views

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Refresh your browser to make sure the course server is running or restart the server in Terminal

Serial vs Concurrent

When you store files on a cloud server, you usually want to know how much storage you’ve used and whether you have duplicate files. This “cloud server” has an endpoint to supply this information.

func status() async throws -> String {
  guard let url = URL(string: "http://localhost:8080/files/status") else {
    throw "Could not create the URL."
  return ""
let (data, response) = try await url) // fetch the data
guard (response as? HTTPURLResponse)?.statusCode == 200 else {  // check the statusCode
  throw "The server responded with an error."
return String(decoding: data, as: UTF8.self)
do {
  files = try await model.availableFiles()
  🟩status = try await model.status()

Grouping async calls

OK, now back to that do closure.

async let files = try model.availableFiles()
async let status = try model.status()
let (filesResult, statusResult) = try await (files, status)
self.files = filesResult
self.status = statusResult