Skip to content

Commit f0832bb

Browse files
committed
apply suggested changes from code review
1 parent 755012b commit f0832bb

File tree

4 files changed

+11
-21
lines changed

4 files changed

+11
-21
lines changed

Examples/GetHTML/GetHTML.swift

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
// TODO: remove @testable after async/await API is public
16-
@testable import AsyncHTTPClient
15+
import AsyncHTTPClient
1716
import NIOCore
1817

19-
#if compiler(>=5.5.2) && canImport(_Concurrency)
20-
2118
@main
22-
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2319
struct GetHTML {
2420
static func main() async throws {
2521
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
@@ -36,5 +32,3 @@ struct GetHTML {
3632
try await httpClient.shutdown()
3733
}
3834
}
39-
40-
#endif

Examples/GetJSON/GetJSON.swift

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

15-
// TODO: remove @testable after async/await API is public
16-
@testable import AsyncHTTPClient
15+
import AsyncHTTPClient
1716
import Foundation
1817
import NIOCore
1918
import NIOFoundationCompat
2019

21-
#if compiler(>=5.5.2) && canImport(_Concurrency)
22-
2320
struct Comic: Codable {
2421
var num: Int
2522
var title: String
@@ -34,7 +31,6 @@ struct Comic: Codable {
3431
}
3532

3633
@main
37-
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
3834
struct GetJSON {
3935
static func main() async throws {
4036
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
@@ -43,6 +39,8 @@ struct GetJSON {
4339
let response = try await httpClient.execute(request, timeout: .seconds(30))
4440
print("HTTP head", response)
4541
let body = try await response.body.collect(upTo: 1024 * 1024) // 1 MB
42+
// we use an overload defined in `NIOFoundationCompat` for `decode(_:from:)` to
43+
// efficiently decode from a `ByteBuffer`
4644
let comic = try JSONDecoder().decode(Comic.self, from: body)
4745
dump(comic)
4846
} catch {
@@ -52,5 +50,3 @@ struct GetJSON {
5250
try await httpClient.shutdown()
5351
}
5452
}
55-
56-
#endif

Examples/Package.swift

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ import PackageDescription
1717

1818
let package = Package(
1919
name: "async-http-client-examples",
20+
platforms: [
21+
.macOS(.v10_15),
22+
.iOS(.v13),
23+
.tvOS(.v13),
24+
.watchOS(.v6),
25+
],
2026
products: [
2127
.executable(name: "GetHTML", targets: ["GetHTML"]),
2228
.executable(name: "GetJSON", targets: ["GetJSON"]),

Examples/StreamingByteCounter/StreamingByteCounter.swift

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
// TODO: remove @testable after async/await API is public
16-
@testable import AsyncHTTPClient
15+
import AsyncHTTPClient
1716
import NIOCore
1817

19-
#if compiler(>=5.5.2) && canImport(_Concurrency)
20-
2118
@main
22-
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2319
struct StreamingByteCounter {
2420
static func main() async throws {
2521
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
@@ -53,5 +49,3 @@ struct StreamingByteCounter {
5349
try await httpClient.shutdown()
5450
}
5551
}
56-
57-
#endif

0 commit comments

Comments
 (0)