@@ -341,36 +341,40 @@ extension WebSocketClient {
341
341
) -> ChannelInitializer {
342
342
@Sendable
343
343
func makeChannelInitializer( _ channel: Channel ) -> EventLoopFuture < Void > {
344
+ let promise = channel. eventLoop. makePromise ( of: Void . self)
344
345
if let deviceName = configuration. deviceName,
345
346
let device = findDevice ( with: deviceName, protocol: resolvedAddress. protocol)
346
347
{
347
348
// bind to selected device, if any
348
- return bindTo ( device: device, on: channel) . flatMap { ( ) -> EventLoopFuture < Void > in
349
- if scheme . enableTLS {
350
- // enale TLS
351
- let tlsConfig = configuration . tlsConfiguration ?? scheme. defaultTLSConfig!
352
- guard let sslContext = try ? NIOSSLContext ( configuration : tlsConfig ) else {
353
- return channel . eventLoop . makeFailedFuture ( LCLWebSocketError . tlsInitializationFailed )
354
- }
355
-
356
- do {
357
- let sslClientHandler = try NIOSSLClientHandler ( context : sslContext , serverHostname : host )
358
- try channel . pipeline . syncOperations . addHandlers ( sslClientHandler )
359
- } catch let error as NIOSSLExtraError where error == . invalidSNIHostname {
360
- do {
361
- let sslClientHandler = try NIOSSLClientHandler ( context : sslContext , serverHostname : nil )
362
- try channel . pipeline . syncOperations . addHandlers ( sslClientHandler )
363
- } catch {
364
- return channel . eventLoop . makeFailedFuture ( error )
365
- }
366
- } catch {
367
- return channel . eventLoop . makeFailedFuture ( error)
368
- }
349
+ bindTo ( device: device, on: channel) . cascadeFailure ( to : promise )
350
+ }
351
+
352
+ if scheme. enableTLS {
353
+ // enale TLS
354
+ let tlsConfig = configuration . tlsConfiguration ?? scheme . defaultTLSConfig!
355
+ guard let sslContext = try ? NIOSSLContext ( configuration : tlsConfig ) else {
356
+ promise . fail ( LCLWebSocketError . tlsInitializationFailed )
357
+ return promise . futureResult
358
+ }
359
+
360
+ do {
361
+ let sslClientHandler = try NIOSSLClientHandler ( context : sslContext , serverHostname : host )
362
+ try channel . pipeline . syncOperations . addHandlers ( sslClientHandler )
363
+ } catch let error as NIOSSLExtraError where error == . invalidSNIHostname {
364
+ do {
365
+ let sslClientHandler = try NIOSSLClientHandler ( context : sslContext , serverHostname : nil )
366
+ try channel . pipeline . syncOperations . addHandlers ( sslClientHandler )
367
+ } catch {
368
+ promise . fail ( error)
369
+ return promise . futureResult
369
370
}
370
- return channel. eventLoop. makeSucceededVoidFuture ( )
371
+ } catch {
372
+ promise. fail ( error)
373
+ return promise. futureResult
371
374
}
372
375
}
373
- return channel. eventLoop. makeSucceededVoidFuture ( )
376
+ promise. succeed ( )
377
+ return promise. futureResult
374
378
}
375
379
376
380
return makeChannelInitializer
0 commit comments