Skip to content
RED SAGSkills
hard20 pts · first answer countsswift-concurrencyactors

Actor reentrancy in an image cache

Two callers ask this actor for the same URL at the same moment. What happens?

actor ImageCache {
  private var cache: [URL: UIImage] = [:]

  func image(for url: URL) async throws -> UIImage {
    if let cached = cache[url] { return cached }
    let image = try await download(url)
    cache[url] = image
    return image
  }
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions