Skip to content

Commit

Permalink
Merge pull request #98 from futuredapp/feature/drop-async-await-support
Browse files Browse the repository at this point in the history
Drop async-await support for Xcode 13.0 and 13.1
  • Loading branch information
mkj-is authored Dec 17, 2021
2 parents 3d25c92 + 2779614 commit cd03622
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 87 deletions.
2 changes: 1 addition & 1 deletion FTAPIKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "FTAPIKit"
s.version = "1.4.1"
s.version = "1.5.0"
s.summary = "Declarative, generic and protocol-oriented REST API framework using URLSession and Codable"
s.description = <<-DESC
Protocol-oriented framework for communication with REST APIs.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ When using Swift package manager install using Xcode 11+
or add following line to your dependencies:

```swift
.package(url: "https://github.com/futuredapp/FTAPIKit.git", from: "1.4.1")
.package(url: "https://github.com/futuredapp/FTAPIKit.git", from: "1.5.0")
```

When using CocoaPods add following line to your `Podfile`:

```ruby
pod 'FTAPIKit', '~> 1.4'
pod 'FTAPIKit', '~> 1.5'
```

## Features
Expand Down
83 changes: 0 additions & 83 deletions Sources/FTAPIKit/URLServer+Async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import Foundation
import FoundationNetworking
#endif

// This extension is duplicated to support Xcode 13.0 and Xcode 13.1,
// where backported concurrency is not available.

// Support of async-await for Xcode 13.2+.
#if swift(>=5.5.2)
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
Expand Down Expand Up @@ -85,84 +82,4 @@ public extension URLServer {
}
}
}

// Support of async-await for Xcode 13 and 13.1.
#elseif swift(>=5.5)
@available(macOS 12, iOS 15, watchOS 8, tvOS 15, *)
public extension URLServer {

/// Performs call to endpoint which does not return any data in the HTTP response.
/// - Note: This call maps ``call(endpoint:completion:)`` to the async/await API
/// - Parameters:
/// - endpoint: The endpoint
/// - Throws: Throws in case that result is .failure
/// - Returns: Void on success
func call(endpoint: Endpoint) async throws {
var task: URLSessionTask?
return try await withTaskCancellationHandler {
try await withCheckedThrowingContinuation { continuation in
task = call(endpoint: endpoint) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
} onCancel: { [task] in
task?.cancel()
}
}

/// Performs call to endpoint which returns an arbitrary data in the HTTP response, that should not be parsed by the decoder of the
/// server.
/// - Note: This call maps ``call(data:completion:)`` to the async/await API
/// - Parameters:
/// - endpoint: The endpoint
/// - Throws: Throws in case that result is .failure
/// - Returns: Plain data returned with the HTTP Response
func call(data endpoint: Endpoint) async throws -> Data {
var task: URLSessionTask?
return try await withTaskCancellationHandler {
try await withCheckedThrowingContinuation { continuation in
task = call(data: endpoint) { result in
switch result {
case .success(let data):
continuation.resume(returning: data)
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
} onCancel: { [task] in
task?.cancel()
}
}

/// Performs call to endpoint which returns data that are supposed to be parsed by the decoder of the instance
/// conforming to ``Server`` in the HTTP response.
/// - Note: This call maps ``call(response:completion:)`` to the async/await API
/// - Parameters:
/// - endpoint: The endpoint
/// - Throws: Throws in case that result is .failure
/// - Returns: Instance of the required type
func call<EP: ResponseEndpoint>(response endpoint: EP) async throws -> EP.Response {
var task: URLSessionTask?
return try await withTaskCancellationHandler {
try await withCheckedThrowingContinuation { continuation in
task = call(response: endpoint) { result in
switch result {
case .success(let response):
continuation.resume(returning: response)
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
} onCancel: { [task] in
task?.cancel()
}
}
}
#endif
2 changes: 1 addition & 1 deletion Tests/FTAPIKitTests/AsyncTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if swift(>=5.5) && !os(Linux)
#if swift(>=5.5.2) && !os(Linux)
import Foundation
import XCTest

Expand Down

0 comments on commit cd03622

Please sign in to comment.