Skip to content

Commit ebe84a3

Browse files
authored
Fix compilation errors when using NIO (#347)
Resolves #346 and should also fix CI on #345. Also updates the example app's `Package.resolved` (which updated itself when I opened the project). Tested using gRPC in the Eliza SPM app. --------- Signed-off-by: Michael Rebello <me@michaelrebello.com>
1 parent bd83d0f commit ebe84a3

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

Examples/ElizaSwiftPackageApp/ElizaSwiftPackageApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Libraries/ConnectNIO/Public/NIOHTTPClient.swift

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
import Connect
1616
import Foundation
1717
import NIOConcurrencyHelpers
18-
@preconcurrency import NIOCore // TODO: Remove once `ChannelHandler` is `Sendable`
18+
@preconcurrency import NIOCore
1919
import NIOHTTP1
20-
@preconcurrency import NIOHTTP2 // TODO: Remove once `HTTP2StreamMultiplexer` is `Sendable`
20+
import NIOHTTP2
2121
import NIOPosix
22-
import NIOSSL
22+
@preconcurrency import NIOSSL
2323
import os.log
2424

2525
/// HTTP client powered by Swift NIO which supports trailers (unlike URLSession).
@@ -193,22 +193,23 @@ open class NIOHTTPClient: Connect.HTTPClientInterface, @unchecked Sendable {
193193
self.state = .connecting
194194
self.bootstrap
195195
.connect(host: self.host, port: self.port)
196-
.flatMap { channel -> EventLoopFuture<(Channel, HTTP2StreamMultiplexer)> in
197-
return channel.pipeline
198-
.handler(type: HTTP2StreamMultiplexer.self)
199-
.map { (channel, $0) }
200-
}
201196
.whenComplete { [weak self] result in
202-
switch result {
203-
case .success((let channel, let multiplexer)):
204-
channel.closeFuture.whenComplete { [weak self] _ in
205-
self?.lock.withLock { self?.state = .disconnected }
206-
}
207-
self?.lock.withLock {
208-
self?.state = .connected(channel: channel, multiplexer: multiplexer)
209-
self?.flushOrFailPendingRequests(using: multiplexer)
197+
do {
198+
switch result {
199+
case .success(let channel):
200+
let multiplexer = try channel.pipeline.syncOperations
201+
.handler(type: HTTP2StreamMultiplexer.self)
202+
channel.closeFuture.whenComplete { [weak self] _ in
203+
self?.lock.withLock { self?.state = .disconnected }
204+
}
205+
self?.lock.withLock {
206+
self?.state = .connected(channel: channel, multiplexer: multiplexer)
207+
self?.flushOrFailPendingRequests(using: multiplexer)
208+
}
209+
case .failure(let error):
210+
throw error
210211
}
211-
case .failure(let error):
212+
} catch let error {
212213
os_log(.error, "NIOHTTPClient disconnected: %@", "\(error)")
213214
self?.lock.withLock {
214215
self?.state = .disconnected

0 commit comments

Comments
 (0)