Approachable Concurrency
// In '-default-isolation MainActor' mode
struct Image {
  // The image cache is safe because it's protected
  // by the main actor.
  static var cachedImage: [URL: Image] = [:]
  static func create(from url: URL) async throws -> Image {
    if let image = cachedImage[url] {
      return image
    }
    let image = try await fetchImage(at: url)
    cachedImage[url] = image
    return image
  }
  // Fetch the data from the given URL and decode it.
  // This is performed on the concurrent thread pool to
  // keep the main actor free while decoding large images.
  @concurrent
  static func fetchImage(at url: URL) async throws -> Image {
    let (data, _) = try await URLSession.shared.data(from: url)
    return await decode(data: data)
  }
}
By running async functions in the caller’s execution context concurrency is more approachable now with Swift 6.2