@@ -341,20 +341,12 @@ 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)
345
- if let deviceName = configuration. deviceName,
346
- let device = findDevice ( with: deviceName, protocol: resolvedAddress. protocol)
347
- {
348
- // bind to selected device, if any
349
- bindTo ( device: device, on: channel) . cascadeFailure ( to: promise)
350
- }
351
-
352
344
if scheme. enableTLS {
353
345
// enale TLS
354
346
let tlsConfig = configuration. tlsConfiguration ?? scheme. defaultTLSConfig!
355
347
guard let sslContext = try ? NIOSSLContext ( configuration: tlsConfig) else {
356
- promise . fail ( LCLWebSocketError . tlsInitializationFailed )
357
- return promise . futureResult
348
+
349
+ return channel . eventLoop . makeFailedFuture ( LCLWebSocketError . tlsInitializationFailed )
358
350
}
359
351
360
352
do {
@@ -365,16 +357,21 @@ extension WebSocketClient {
365
357
let sslClientHandler = try NIOSSLClientHandler ( context: sslContext, serverHostname: nil )
366
358
try channel. pipeline. syncOperations. addHandlers ( sslClientHandler)
367
359
} catch {
368
- promise. fail ( error)
369
- return promise. futureResult
360
+ return channel. eventLoop. makeFailedFuture ( error)
370
361
}
371
362
} catch {
372
- promise. fail ( error)
373
- return promise. futureResult
363
+ return channel. eventLoop. makeFailedFuture ( error)
374
364
}
375
365
}
376
- promise. succeed ( )
377
- return promise. futureResult
366
+
367
+ if let deviceName = configuration. deviceName,
368
+ let device = findDevice ( with: deviceName, protocol: resolvedAddress. protocol)
369
+ {
370
+ // bind to selected device, if any
371
+ return bindTo ( device: device, on: channel)
372
+ }
373
+
374
+ return channel. eventLoop. makeSucceededVoidFuture ( )
378
375
}
379
376
380
377
return makeChannelInitializer
0 commit comments