[Swift Concurrency] Async/await

[iOS - swift] Async, Await 사용 방법

[Swift] async / await & concurrency

1. Async, Awiat


1.1 기존의 비동기 처리 방법

// DispatchQueue를 사용한 비동기 처리
DispatchQueue.global.async {
	//코드 작성
}

// completionHandler를 사용한 비동기 처리
let task = URLSession.shared.dataTask(with: url, completionHandler: { 
	data: response, error in
	//코드 작성
}).resume()

1.2 async, await 도입 후

func loadWebResource(_ path: String) async throws -> Resource
func decodeImage(_ r1: Resource, _ r2: Resource) async thorws -> Image
func dewarpAndCleanupImage(_ i : Image) async thorws -> Image

func processImageData() async thorws -> Image {
	let dataResource = try await loadWebResource("dataprofile.txt")
	let imageResource = try await loadWebResource("imagedata.dat")
	let imageTmp = try await decodeImage(dataResource, imageResource)
	let imageResource = try await dewarpAndCleanupImage(imageTmp)
	return imageResult
}