@@ -3,9 +3,6 @@ import Foundation
33import FoundationNetworking
44#endif
55
6- // This extension is duplicated to support Xcode 13.0 and Xcode 13.1,
7- // where backported concurrency is not available.
8-
96// Support of async-await for Xcode 13.2+.
107#if swift(>=5.5.2)
118@available ( macOS 10 . 15 , iOS 13 , watchOS 6 , tvOS 13 , * )
@@ -85,84 +82,4 @@ public extension URLServer {
8582 }
8683 }
8784}
88-
89- // Support of async-await for Xcode 13 and 13.1.
90- #elseif swift(>=5.5)
91- @available ( macOS 12 , iOS 15 , watchOS 8 , tvOS 15 , * )
92- public extension URLServer {
93-
94- /// Performs call to endpoint which does not return any data in the HTTP response.
95- /// - Note: This call maps ``call(endpoint:completion:)`` to the async/await API
96- /// - Parameters:
97- /// - endpoint: The endpoint
98- /// - Throws: Throws in case that result is .failure
99- /// - Returns: Void on success
100- func call( endpoint: Endpoint ) async throws {
101- var task : URLSessionTask ?
102- return try await withTaskCancellationHandler {
103- try await withCheckedThrowingContinuation { continuation in
104- task = call ( endpoint: endpoint) { result in
105- switch result {
106- case . success:
107- continuation. resume ( )
108- case . failure( let error) :
109- continuation. resume ( throwing: error)
110- }
111- }
112- }
113- } onCancel: { [ task] in
114- task? . cancel ( )
115- }
116- }
117-
118- /// Performs call to endpoint which returns an arbitrary data in the HTTP response, that should not be parsed by the decoder of the
119- /// server.
120- /// - Note: This call maps ``call(data:completion:)`` to the async/await API
121- /// - Parameters:
122- /// - endpoint: The endpoint
123- /// - Throws: Throws in case that result is .failure
124- /// - Returns: Plain data returned with the HTTP Response
125- func call( data endpoint: Endpoint ) async throws -> Data {
126- var task : URLSessionTask ?
127- return try await withTaskCancellationHandler {
128- try await withCheckedThrowingContinuation { continuation in
129- task = call ( data: endpoint) { result in
130- switch result {
131- case . success( let data) :
132- continuation. resume ( returning: data)
133- case . failure( let error) :
134- continuation. resume ( throwing: error)
135- }
136- }
137- }
138- } onCancel: { [ task] in
139- task? . cancel ( )
140- }
141- }
142-
143- /// Performs call to endpoint which returns data that are supposed to be parsed by the decoder of the instance
144- /// conforming to ``Server`` in the HTTP response.
145- /// - Note: This call maps ``call(response:completion:)`` to the async/await API
146- /// - Parameters:
147- /// - endpoint: The endpoint
148- /// - Throws: Throws in case that result is .failure
149- /// - Returns: Instance of the required type
150- func call< EP: ResponseEndpoint > ( response endpoint: EP ) async throws -> EP . Response {
151- var task : URLSessionTask ?
152- return try await withTaskCancellationHandler {
153- try await withCheckedThrowingContinuation { continuation in
154- task = call ( response: endpoint) { result in
155- switch result {
156- case . success( let response) :
157- continuation. resume ( returning: response)
158- case . failure( let error) :
159- continuation. resume ( throwing: error)
160- }
161- }
162- }
163- } onCancel: { [ task] in
164- task? . cancel ( )
165- }
166- }
167- }
16885#endif
0 commit comments