Geon

Modern Concurrency Deep Dive(4) 본문

iOS developer essential skills/Modern Concurency

Modern Concurrency Deep Dive(4)

jgkim1008 2024. 11. 17. 20:13

WithUnsafeContinuation

- 런타임중 확인을 안하기에, continuation이 두번 호출되면 앱이 크래시가 난다.

 

WithCheckedContinuation

- 런타임중 확인을 하기에, continuation을 두번 호출해도 안전하다.

 

func asyncFetchImage() async -> UIImage? {
 return await withCheckedContinuation { continuation in 
  fetchImage { image in
  continuation.resume(with.success(image))
  continuation.resume(with.success(image)) // checked 라 안전
 }
}