Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- APNS
- 오블완
- ios
- WWDC
- modern concurrency deep dive
- 야곰 # 야곰아카데미커리어스타터캠프 #iOS개발자 # 부트캠프
- modern concurrency
- 티스토리챌린지
- SWIFT
Archives
- Today
- Total
Geon
Modern Concurrency Deep Dive(13) 본문
iOS developer essential skills/Modern Concurency
Modern Concurrency Deep Dive(13)
jgkim1008 2024. 11. 26. 23:27TaskGroup Cancel
- 취소 전파 가능하다.
- 내부적으로 취소를 어떻게 처리할지는 구현자의 몫
- nil로 처리후 넘어갈지, 취소처리 할지 구현가능하다.
func groupFunction() async -> [UIImage] {
try await withThrowingTaskGroup(of: UIImage?.self) { group in
var result: [UIImage] = []
for 1..<100 {
let image = try? await someAsyncFunction() // cancel시 nil 로 에러처리후 취소되지 않고 진행
// let image = try await someAsnycFunction() // cancel시 taskStop됨
return image
}
for try await image in group {
if let image = image {
result.append(image)
}
}
}
return result
}
func someAsyncFunction() asnyc throws -> UIImage {
do {
let (data, _) = try await URLSession.shared.data(from: url)
guard let image = UIImage(data: data) else {
throw ImageError
}
return image
} catch {
if let error = error as? URLError, error.code == .cancelled {
throw cancelErorr
} else {
throw URLError
}
}
'iOS developer essential skills > Modern Concurency' 카테고리의 다른 글
Modern Concurrency Deep Dive(15) (0) | 2024.11.28 |
---|---|
Modern Concurrency Deep Dive(14) (0) | 2024.11.27 |
Modern Concurrency Deep Dive(12) (0) | 2024.11.25 |
Modern Concurrency Deep Dive(11) (0) | 2024.11.24 |
Modern Concurrency Deep Dive(10) (0) | 2024.11.23 |