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
}
}Discussion 0
Join free to post in the discussion.