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
- 야곰 # 야곰아카데미커리어스타터캠프 #iOS개발자 # 부트캠프
- modern concurrency
- ios
- SWIFT
- 티스토리챌린지
- modern concurrency deep dive
- APNS
- WWDC
- 오블완
Archives
- Today
- Total
Geon
Modern Concurrency Deep Dive(7) 본문
iOS developer essential skills/Modern Concurency
Modern Concurrency Deep Dive(7)
jgkim1008 2024. 11. 20. 23:37Task.Sleep
- GCD의 sleep과 Task.sleep의 차이는 blocking과 Non-blocking의 차이이다
- GCD의 sleep은 blocking 됨(mainThread에 사용하면 안됨)
- Task의 sleep은 sleep되면 시스템에 Thread를 반납해 다른 동작을 처리할수 있음.
병렬 처리가 아닌경우
func fetch(urlArray: [String]) async -> [UIImage] {
var array: [UIImage] = []
for url in urlArray {
// 하나 실행되고 기다리고 하나실행됨(병렬 처리가 아님)
if let image = await fetchImage(url) {
array.append(image)
}
//TODO: - 병렬처리
Task {
if let image = await fetchImage(url) {
array.append(image)
}
}
}
}
- task 로 묶어 하나의 비동기 작업으로 구현하여 기다리지 fetchImage를 기다리지 않고 계속 for문을 실행
'iOS developer essential skills > Modern Concurency' 카테고리의 다른 글
Modern Concurrency Deep Dive(9) (0) | 2024.11.22 |
---|---|
Modern Concurrency Deep Dive(8) (0) | 2024.11.21 |
Modern Concurrency Deep Dive(6) (0) | 2024.11.19 |
Modern Concurrency Deep Dive(5) (0) | 2024.11.18 |
Modern Concurrency Deep Dive(4) (0) | 2024.11.17 |