Skip to content

Commit d372bdc

Browse files
authored
Make async/await available on older Apple Platforms (#527)
### 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 e4b11eb commit d372bdc

12 files changed

+132
-132
lines changed

Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+execute.swift

+4-4
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,
@@ -124,7 +124,7 @@ extension HTTPClient {
124124
/// There is currently no good way to asynchronously cancel an object that is initiated inside the `body` closure of `with*Continuation`.
125125
/// As a workaround we use `TransactionCancelHandler` which will take care of the race between instantiation of `Transaction`
126126
/// in the `body` closure and cancelation from the `onCancel` closure of `withTaskCancellationHandler`.
127-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
127+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
128128
private actor TransactionCancelHandler {
129129
enum CancelReason {
130130
/// swift concurrency task was canceled

Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest+Prepared.swift

+5-5
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

+5-5
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

+5-5
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

+2-2
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

+5-5
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

@@ -316,7 +316,7 @@ extension Transaction: HTTPExecutableRequest {
316316
}
317317
}
318318

319-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
319+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
320320
extension Transaction {
321321
func responseBodyDeinited() {
322322
let deinitedAction = self.stateLock.withLock {

Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift

+29-29
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ private func makeDefaultHTTPClient(
3434

3535
final class AsyncAwaitEndToEndTests: XCTestCase {
3636
func testSimpleGet() {
37-
#if compiler(>=5.5) && canImport(_Concurrency)
38-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
37+
#if compiler(>=5.5.2) && canImport(_Concurrency)
38+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
3939
XCTAsyncTest {
4040
let bin = HTTPBin(.http2(compress: false))
4141
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -57,8 +57,8 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
5757
}
5858

5959
func testSimplePost() {
60-
#if compiler(>=5.5) && canImport(_Concurrency)
61-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
60+
#if compiler(>=5.5.2) && canImport(_Concurrency)
61+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
6262
XCTAsyncTest {
6363
let bin = HTTPBin(.http2(compress: false))
6464
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -80,8 +80,8 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
8080
}
8181

8282
func testPostWithByteBuffer() {
83-
#if compiler(>=5.5) && canImport(_Concurrency)
84-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
83+
#if compiler(>=5.5.2) && canImport(_Concurrency)
84+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
8585
XCTAsyncTest {
8686
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
8787
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -105,8 +105,8 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
105105
}
106106

107107
func testPostWithSequenceOfUInt8() {
108-
#if compiler(>=5.5) && canImport(_Concurrency)
109-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
108+
#if compiler(>=5.5.2) && canImport(_Concurrency)
109+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
110110
XCTAsyncTest {
111111
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
112112
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -130,8 +130,8 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
130130
}
131131

132132
func testPostWithCollectionOfUInt8() {
133-
#if compiler(>=5.5) && canImport(_Concurrency)
134-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
133+
#if compiler(>=5.5.2) && canImport(_Concurrency)
134+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
135135
XCTAsyncTest {
136136
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
137137
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -155,8 +155,8 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
155155
}
156156

157157
func testPostWithRandomAccessCollectionOfUInt8() {
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 bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
162162
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -180,8 +180,8 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
180180
}
181181

182182
func testPostWithAsyncSequenceOfByteBuffers() {
183-
#if compiler(>=5.5) && canImport(_Concurrency)
184-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
183+
#if compiler(>=5.5.2) && canImport(_Concurrency)
184+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
185185
XCTAsyncTest {
186186
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
187187
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -209,8 +209,8 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
209209
}
210210

211211
func testPostWithAsyncSequenceOfUInt8() {
212-
#if compiler(>=5.5) && canImport(_Concurrency)
213-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
212+
#if compiler(>=5.5.2) && canImport(_Concurrency)
213+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
214214
XCTAsyncTest {
215215
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
216216
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -234,8 +234,8 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
234234
}
235235

236236
func testPostWithFragmentedAsyncSequenceOfByteBuffers() {
237-
#if compiler(>=5.5) && canImport(_Concurrency)
238-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
237+
#if compiler(>=5.5.2) && canImport(_Concurrency)
238+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
239239
XCTAsyncTest {
240240
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
241241
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -276,8 +276,8 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
276276
}
277277

278278
func testPostWithFragmentedAsyncSequenceOfLargeByteBuffers() {
279-
#if compiler(>=5.5) && canImport(_Concurrency)
280-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
279+
#if compiler(>=5.5.2) && canImport(_Concurrency)
280+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
281281
XCTAsyncTest {
282282
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
283283
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -319,8 +319,8 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
319319
}
320320

321321
func testCanceling() {
322-
#if compiler(>=5.5) && canImport(_Concurrency)
323-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
322+
#if compiler(>=5.5.2) && canImport(_Concurrency)
323+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
324324
XCTAsyncTest(timeout: 5) {
325325
let bin = HTTPBin(.http2(compress: false))
326326
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -344,8 +344,8 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
344344
}
345345

346346
func testDeadline() {
347-
#if compiler(>=5.5) && canImport(_Concurrency)
348-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
347+
#if compiler(>=5.5.2) && canImport(_Concurrency)
348+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
349349
XCTAsyncTest(timeout: 5) {
350350
let bin = HTTPBin(.http2(compress: false))
351351
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -365,8 +365,8 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
365365
}
366366

367367
func testImmediateDeadline() {
368-
#if compiler(>=5.5) && canImport(_Concurrency)
369-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
368+
#if compiler(>=5.5.2) && canImport(_Concurrency)
369+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
370370
XCTAsyncTest(timeout: 5) {
371371
let bin = HTTPBin(.http2(compress: false))
372372
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -386,8 +386,8 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
386386
}
387387

388388
func testInvalidURL() {
389-
#if compiler(>=5.5) && canImport(_Concurrency)
390-
guard #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) else { return }
389+
#if compiler(>=5.5.2) && canImport(_Concurrency)
390+
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
391391
XCTAsyncTest(timeout: 5) {
392392
let client = makeDefaultHTTPClient()
393393
defer { XCTAssertNoThrow(try client.syncShutdown()) }
@@ -402,7 +402,7 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
402402
}
403403
}
404404

405-
#if compiler(>=5.5) && canImport(_Concurrency)
405+
#if compiler(>=5.5.2) && canImport(_Concurrency)
406406
extension AsyncSequence where Element == ByteBuffer {
407407
func collect() async rethrows -> ByteBuffer {
408408
try await self.reduce(into: ByteBuffer()) { accumulatingBuffer, nextBuffer in

Tests/AsyncHTTPClientTests/AsyncTestHelpers.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#if swift(>=5.5) && canImport(_Concurrency)
15+
#if compiler(>=5.5.2) && canImport(_Concurrency)
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

0 commit comments

Comments
 (0)