Alamofire + Swift Concurrency

Support for the Swift Concurrency features has been implemented for DataRequests and is tracked in this draft PR. You can now await requests in Alamofire through the production of DataTask values, which encapsulate an underlying Task.Handle and DataRequest.

let dataTask = AF.request(url).decode(SomeType.self)
let response = await dataTask.response
let result = await dataTask.result
let value = try await dataTask.value

Support for other request types should follow over the coming weeks and months. If anyone has suggestions for naming for functionality, feel free to post it in this thread.

8 Likes

This linked PR has now largely been finalized in preparation for the release of Xcode 13.2 soon. Please feel free to review the APIs, paying special attention to any features you'd like to see, the naming, and the use of specific queues for completion events in the concurrency features. APIs have been standardized around the serializing or streaming terminology.

let dataTask = AF.request(...).serializingDecodable(SomeType.self)
let response = await dataTask.response
let result = await dataTask.result
let value = try await dataTask.value

I'm not a huge fan of the various *Task types for the wrapper which produce the async interface, but I couldn't think of anything that would be part of the common concurrency terminology while not just being redundant like AsyncResponse.

3 Likes