Created
January 30, 2023 07:38
-
-
Save erdemildiz/5d1a133893233e5ab81d3ceec9e0316f to your computer and use it in GitHub Desktop.
Revisions
-
erdemildiz revised this gist
Jan 30, 2023 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ // Source: https://www.avanderlee.com/concurrency/task-groups-in-swift/ let images = try await withThrowingTaskGroup(of: UIImage.self, returning: [UIImage].self) { taskGroup in let photoURLs = try await listPhotoURLs(inGallery: "Amsterdam Holiday") for photoURL in photoURLs { -
erdemildiz created this gist
Jan 30, 2023 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ let images = try await withThrowingTaskGroup(of: UIImage.self, returning: [UIImage].self) { taskGroup in let photoURLs = try await listPhotoURLs(inGallery: "Amsterdam Holiday") for photoURL in photoURLs { taskGroup.addTask { try await downloadPhoto(url: photoURL) } } var images = [UIImage]() /// Note the use of `next()`: while let downloadImage = try await taskGroup.next() { images.append(downloadImage) } return images }