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

Save for later
About this episode
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 9. Your Second Asynchronous App Next episode: 11. Using Asynchronous Methods in Views

This video Concurrency With async let was last updated on Oct 18 2022

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

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a Professional subscription.

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