Created
March 19, 2025 07:25
-
-
Save gaeng2y/3ac69c06fcb1a13777bd55b4290774ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func fetchThumbnails(for ids: [String]) async throws -> [String: UIImage] { | |
| var thumbnails: [String: UIImage] = [:] | |
| try await withThrowingTaskGroup(of: (String, UIImage).self) { group in | |
| for id in ids { | |
| group.async { | |
| return (id, try await fetchOneThumbnail(withID: id)) | |
| } | |
| } | |
| // Obtain results from the child tasks, sequentially, in order of completion. | |
| for try await (id, thumbnail) in group { | |
| thumbnails[id] = thumbnail | |
| } | |
| } | |
| return thumbnails | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment