Skip to content

Commit da451be

Browse files
committed
Start to switch over to NIO Transport Services
1 parent 7aeaf6f commit da451be

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ let package = Package(
2424
.package(url: "https://github.com/apple/swift-nio.git", from: "2.10.1"),
2525
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.0.0"),
2626
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.3.0"),
27+
.package(url: "https://github.com/apple/swift-nio-transport-services", from: "1.0.0")
2728
],
2829
targets: [
2930
.target(
3031
name: "AsyncHTTPClient",
31-
dependencies: ["NIO", "NIOHTTP1", "NIOSSL", "NIOConcurrencyHelpers", "NIOHTTPCompression", "NIOFoundationCompat"]
32+
dependencies: ["NIO", "NIOHTTP1", "NIOSSL", "NIOTransportServices", "NIOConcurrencyHelpers", "NIOHTTPCompression", "NIOFoundationCompat"]
3233
),
3334
.testTarget(
3435
name: "AsyncHTTPClientTests",

Sources/AsyncHTTPClient/HTTPClient.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import NIOConcurrencyHelpers
1818
import NIOHTTP1
1919
import NIOHTTPCompression
2020
import NIOSSL
21+
#if canImport(Network)
22+
import Network
23+
import NIOTransportServices
24+
#endif
2125

2226
/// HTTPClient class provides API for request execution.
2327
///
@@ -61,7 +65,15 @@ public class HTTPClient {
6165
case .shared(let group):
6266
self.eventLoopGroup = group
6367
case .createNew:
64-
self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
68+
#if canImport(Network)
69+
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) {
70+
self.eventLoopGroup = NIOTSEventLoopGroup()
71+
} else {
72+
self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
73+
}
74+
#else
75+
self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
76+
#endif
6577
}
6678
self.configuration = configuration
6779
}

0 commit comments

Comments
 (0)