Skip to content

Commit 97d9709

Browse files
committed
make async/await available on older platforms
### Motivation With Xcode 13.2, and therefore Swift 5.5.2, Swift Concurrecy is supported on older Apple OSs. async/await suport will no longer be available on Swift before `5.5.2` but this isn't a breaking change because we have not yet made anything of it public. ### Changes - replace all `#if compiler(>=5.5) && canImport(_Concurrency)` with `#if compiler(>=5.5.2) && canImport(_Concurrency)` - replace all `available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)` with `available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)`
1 parent 5db7719 commit 97d9709

10 files changed

+89
-89
lines changed

Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+execute.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#if compiler(>=5.5) && canImport(_Concurrency)
15+
#if compiler(>=5.5.2) && canImport(_Concurrency)
1616
import struct Foundation.URL
1717
import Logging
1818
import NIOCore
1919
import NIOHTTP1
2020

21-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
21+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2222
extension HTTPClient {
2323
/// Execute arbitrary HTTP requests.
2424
///
@@ -41,7 +41,7 @@ extension HTTPClient {
4141
}
4242
}
4343

44-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
44+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
4545
extension HTTPClient {
4646
private func executeAndFollowRedirectsIfNeeded(
4747
_ request: HTTPClientRequest,
@@ -117,7 +117,7 @@ extension HTTPClient {
117117
/// There is currently no good way to asynchronously cancel an object that is initiated inside the `body` closure of `with*Continuation`.
118118
/// As a workaround we use `TransactionCancelHandler` which will take care of the race between instantiation of `Transaction`
119119
/// in the `body` closure and cancelation from the `onCancel` closure of `withTaskCancellationHandler`.
120-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
120+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
121121
private actor TransactionCancelHandler {
122122
private enum State {
123123
case initialised

Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest+Prepared.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#if compiler(>=5.5) && canImport(_Concurrency)
15+
#if compiler(>=5.5.2) && canImport(_Concurrency)
1616
import struct Foundation.URL
1717
import NIOHTTP1
1818

19-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
19+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2020
extension HTTPClientRequest {
2121
struct Prepared {
2222
var url: URL
@@ -27,7 +27,7 @@ extension HTTPClientRequest {
2727
}
2828
}
2929

30-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
30+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
3131
extension HTTPClientRequest.Prepared {
3232
init(_ request: HTTPClientRequest) throws {
3333
guard let url = URL(string: request.url) else {
@@ -58,7 +58,7 @@ extension HTTPClientRequest.Prepared {
5858
}
5959
}
6060

61-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
61+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
6262
extension RequestBodyLength {
6363
init(_ body: HTTPClientRequest.Body?) {
6464
switch body?.mode {
@@ -74,7 +74,7 @@ extension RequestBodyLength {
7474
}
7575
}
7676

77-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
77+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
7878
extension HTTPClientRequest.Prepared {
7979
func followingRedirect(to redirectURL: URL, status: HTTPResponseStatus) -> HTTPClientRequest {
8080
let (method, headers, body) = transformRequestForRedirect(

Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#if compiler(>=5.5) && canImport(_Concurrency)
15+
#if compiler(>=5.5.2) && canImport(_Concurrency)
1616
import NIOCore
1717
import NIOHTTP1
1818

19-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
19+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2020
struct HTTPClientRequest {
2121
var url: String
2222
var method: HTTPMethod
@@ -32,7 +32,7 @@ struct HTTPClientRequest {
3232
}
3333
}
3434

35-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
35+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
3636
extension HTTPClientRequest {
3737
struct Body {
3838
internal enum Mode {
@@ -49,7 +49,7 @@ extension HTTPClientRequest {
4949
}
5050
}
5151

52-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
52+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
5353
extension HTTPClientRequest.Body {
5454
static func byteBuffer(_ byteBuffer: ByteBuffer) -> Self {
5555
self.init(.byteBuffer(byteBuffer))
@@ -131,7 +131,7 @@ extension HTTPClientRequest.Body {
131131
}
132132
}
133133

134-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
134+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
135135
extension Optional where Wrapped == HTTPClientRequest.Body {
136136
internal var canBeConsumedMultipleTimes: Bool {
137137
switch self?.mode {

Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#if compiler(>=5.5) && canImport(_Concurrency)
15+
#if compiler(>=5.5.2) && canImport(_Concurrency)
1616
import NIOCore
1717
import NIOHTTP1
1818

19-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
19+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2020
struct HTTPClientResponse {
2121
var version: HTTPVersion
2222
var status: HTTPResponseStatus
@@ -46,7 +46,7 @@ struct HTTPClientResponse {
4646
}
4747
}
4848

49-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
49+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
5050
extension HTTPClientResponse.Body: AsyncSequence {
5151
typealias Element = ByteBuffer
5252
typealias AsyncIterator = Iterator
@@ -70,7 +70,7 @@ extension HTTPClientResponse.Body: AsyncSequence {
7070
}
7171
}
7272

73-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
73+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
7474
extension HTTPClientResponse.Body {
7575
/// The purpose of this object is to inform the transaction about the response body being deinitialized.
7676
/// If the users has not called `makeAsyncIterator` on the body, before it is deinited, the http
@@ -88,7 +88,7 @@ extension HTTPClientResponse.Body {
8888
}
8989
}
9090

91-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
91+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
9292
extension HTTPClientResponse.Body {
9393
internal class IteratorStream {
9494
struct ID: Hashable {

Sources/AsyncHTTPClient/AsyncAwait/Transaction+StateMachine.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
// SPDX-License-Identifier: Apache-2.0
1212
//
1313
//===----------------------------------------------------------------------===//
14-
#if compiler(>=5.5) && canImport(_Concurrency)
14+
#if compiler(>=5.5.2) && canImport(_Concurrency)
1515
import Logging
1616
import NIOCore
1717
import NIOHTTP1
1818

19-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
19+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2020
extension Transaction {
2121
struct StateMachine {
2222
struct ExecutionContext {

Sources/AsyncHTTPClient/AsyncAwait/Transaction.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#if compiler(>=5.5) && canImport(_Concurrency)
15+
#if compiler(>=5.5.2) && canImport(_Concurrency)
1616
import Logging
1717
import NIOConcurrencyHelpers
1818
import NIOCore
1919
import NIOHTTP1
2020
import NIOSSL
2121

22-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
22+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2323
final class Transaction: @unchecked Sendable {
2424
let logger: Logger
2525

@@ -145,7 +145,7 @@ final class Transaction: @unchecked Sendable {
145145

146146
// MARK: - Protocol Methods -
147147

148-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
148+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
149149
extension Transaction: HTTPSchedulableRequest {
150150
var poolKey: ConnectionPool.Key { self.request.poolKey }
151151
var tlsConfiguration: TLSConfiguration? { return nil }
@@ -158,7 +158,7 @@ extension Transaction: HTTPSchedulableRequest {
158158
}
159159
}
160160

161-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
161+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
162162
extension Transaction: HTTPExecutableRequest {
163163
var requestHead: HTTPRequestHead { self.request.head }
164164

@@ -296,7 +296,7 @@ extension Transaction: HTTPExecutableRequest {
296296
}
297297
}
298298

299-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
299+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
300300
extension Transaction {
301301
func responseBodyDeinited() {
302302
let deinitedAction = self.stateLock.withLock {

Tests/AsyncHTTPClientTests/AsyncTestHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import NIOConcurrencyHelpers
1717
import NIOCore
1818

19-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
19+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2020
class AsyncSequenceWriter<Element>: AsyncSequence {
2121
typealias AsyncIterator = Iterator
2222

Tests/AsyncHTTPClientTests/HTTPClientRequestTests.swift

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ import NIOCore
1717
import XCTest
1818

1919
class HTTPClientRequestTests: XCTestCase {
20-
#if compiler(>=5.5) && canImport(_Concurrency)
21-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
20+
#if compiler(>=5.5.2) && canImport(_Concurrency)
21+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2222
private typealias Request = HTTPClientRequest
2323

24-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
24+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2525
private typealias PreparedRequest = HTTPClientRequest.Prepared
2626
#endif
2727

2828
func testCustomHeadersAreRespected() {
29-
#if compiler(>=5.5) && canImport(_Concurrency)
30-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
29+
#if compiler(>=5.5.2) && canImport(_Concurrency)
30+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
3131
XCTAsyncTest {
3232
var request = Request(url: "https://example.com/get")
3333
request.headers = [
@@ -62,8 +62,8 @@ class HTTPClientRequestTests: XCTestCase {
6262
}
6363

6464
func testUnixScheme() {
65-
#if compiler(>=5.5) && canImport(_Concurrency)
66-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
65+
#if compiler(>=5.5.2) && canImport(_Concurrency)
66+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
6767
XCTAsyncTest {
6868
var request = Request(url: "unix://%2Fexample%2Ffolder.sock/some_path")
6969
request.headers = ["custom-header": "custom-value"]
@@ -93,8 +93,8 @@ class HTTPClientRequestTests: XCTestCase {
9393
}
9494

9595
func testHTTPUnixScheme() {
96-
#if compiler(>=5.5) && canImport(_Concurrency)
97-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
96+
#if compiler(>=5.5.2) && canImport(_Concurrency)
97+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
9898
XCTAsyncTest {
9999
var request = Request(url: "http+unix://%2Fexample%2Ffolder.sock/some_path")
100100
request.headers = ["custom-header": "custom-value"]
@@ -124,8 +124,8 @@ class HTTPClientRequestTests: XCTestCase {
124124
}
125125

126126
func testHTTPSUnixScheme() {
127-
#if compiler(>=5.5) && canImport(_Concurrency)
128-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
127+
#if compiler(>=5.5.2) && canImport(_Concurrency)
128+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
129129
XCTAsyncTest {
130130
var request = Request(url: "https+unix://%2Fexample%2Ffolder.sock/some_path")
131131
request.headers = ["custom-header": "custom-value"]
@@ -155,8 +155,8 @@ class HTTPClientRequestTests: XCTestCase {
155155
}
156156

157157
func testGetWithoutBody() {
158-
#if compiler(>=5.5) && canImport(_Concurrency)
159-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
158+
#if compiler(>=5.5.2) && canImport(_Concurrency)
159+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
160160
XCTAsyncTest {
161161
let request = Request(url: "https://example.com/get")
162162
var preparedRequest: PreparedRequest?
@@ -185,8 +185,8 @@ class HTTPClientRequestTests: XCTestCase {
185185
}
186186

187187
func testPostWithoutBody() {
188-
#if compiler(>=5.5) && canImport(_Concurrency)
189-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
188+
#if compiler(>=5.5.2) && canImport(_Concurrency)
189+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
190190
XCTAsyncTest {
191191
var request = Request(url: "http://example.com/post")
192192
request.method = .POST
@@ -220,8 +220,8 @@ class HTTPClientRequestTests: XCTestCase {
220220
}
221221

222222
func testPostWithEmptyByteBuffer() {
223-
#if compiler(>=5.5) && canImport(_Concurrency)
224-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
223+
#if compiler(>=5.5.2) && canImport(_Concurrency)
224+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
225225
XCTAsyncTest {
226226
var request = Request(url: "http://example.com/post")
227227
request.method = .POST
@@ -256,8 +256,8 @@ class HTTPClientRequestTests: XCTestCase {
256256
}
257257

258258
func testPostWithByteBuffer() {
259-
#if compiler(>=5.5) && canImport(_Concurrency)
260-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
259+
#if compiler(>=5.5.2) && canImport(_Concurrency)
260+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
261261
XCTAsyncTest {
262262
var request = Request(url: "http://example.com/post")
263263
request.method = .POST
@@ -291,8 +291,8 @@ class HTTPClientRequestTests: XCTestCase {
291291
}
292292

293293
func testPostWithSequenceOfUnknownLength() {
294-
#if compiler(>=5.5) && canImport(_Concurrency)
295-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
294+
#if compiler(>=5.5.2) && canImport(_Concurrency)
295+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
296296
XCTAsyncTest {
297297
var request = Request(url: "http://example.com/post")
298298
request.method = .POST
@@ -327,8 +327,8 @@ class HTTPClientRequestTests: XCTestCase {
327327
}
328328

329329
func testPostWithSequenceWithFixedLength() {
330-
#if compiler(>=5.5) && canImport(_Concurrency)
331-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
330+
#if compiler(>=5.5.2) && canImport(_Concurrency)
331+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
332332
XCTAsyncTest {
333333
var request = Request(url: "http://example.com/post")
334334
request.method = .POST
@@ -364,8 +364,8 @@ class HTTPClientRequestTests: XCTestCase {
364364
}
365365

366366
func testPostWithRandomAccessCollection() {
367-
#if compiler(>=5.5) && canImport(_Concurrency)
368-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
367+
#if compiler(>=5.5.2) && canImport(_Concurrency)
368+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
369369
XCTAsyncTest {
370370
var request = Request(url: "http://example.com/post")
371371
request.method = .POST
@@ -400,8 +400,8 @@ class HTTPClientRequestTests: XCTestCase {
400400
}
401401

402402
func testPostWithAsyncSequenceOfUnknownLength() {
403-
#if compiler(>=5.5) && canImport(_Concurrency)
404-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
403+
#if compiler(>=5.5.2) && canImport(_Concurrency)
404+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
405405
XCTAsyncTest {
406406
var request = Request(url: "http://example.com/post")
407407
request.method = .POST
@@ -441,8 +441,8 @@ class HTTPClientRequestTests: XCTestCase {
441441
}
442442

443443
func testPostWithAsyncSequenceWithKnownLength() {
444-
#if compiler(>=5.5) && canImport(_Concurrency)
445-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
444+
#if compiler(>=5.5.2) && canImport(_Concurrency)
445+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
446446
XCTAsyncTest {
447447
var request = Request(url: "http://example.com/post")
448448
request.method = .POST
@@ -482,13 +482,13 @@ class HTTPClientRequestTests: XCTestCase {
482482
}
483483
}
484484

485-
#if compiler(>=5.5) && canImport(_Concurrency)
485+
#if compiler(>=5.5.2) && canImport(_Concurrency)
486486
private struct LengthMismatch: Error {
487487
var announcedLength: Int
488488
var actualLength: Int
489489
}
490490

491-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
491+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
492492
extension Optional where Wrapped == HTTPClientRequest.Body {
493493
/// Accumulates all data from `self` into a single `ByteBuffer` and checks that the user specified length matches
494494
/// the length of the accumulated data.

0 commit comments

Comments
 (0)