Merging same-URL downloads
In a photo grid, several cells request the same photo URL at the same time, but the network download must happen only once. How would you keep in-flight Tasks inside an actor to merge the requests?
In a photo grid, several cells request the same photo URL at the same time, but the network download must happen only once. How would you keep in-flight Tasks inside an actor to merge the requests?
Keep a [URL: Task<UIImage, Error>] dictionary keyed by URL inside the actor; when a request comes in, if a Task for that URL already exists, await its value, and if not, create a new Task, put it in the dictionary first, then await it. The second cell doesn't start a download and shares the first Task's result.
ConcurrencyShort answerBasics
This code gets called from several threads, and count comes out lower than expected. Can…
#actor
ConcurrencyShort answerBasics
In Swift Concurrency, when you create a Task { }, when and where does that code run?
#task
ConcurrencyShort answerExpert
This image cache actor built with Swift Concurrency sometimes sends two network requests…
#actor
ConcurrencyMultiple choiceAdvanced
Under Swift 6 strict concurrency, which of the following are treated as Sendable (or…
#actor