Skip to content

Commit e1ad0b1

Browse files
committed
refactor
1 parent ffa2bed commit e1ad0b1

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

Sources/LCLWebSocket/Client/WebSocketClient.swift

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -341,20 +341,12 @@ extension WebSocketClient {
341341
) -> ChannelInitializer {
342342
@Sendable
343343
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-
352344
if scheme.enableTLS {
353345
// enale TLS
354346
let tlsConfig = configuration.tlsConfiguration ?? scheme.defaultTLSConfig!
355347
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)
358350
}
359351

360352
do {
@@ -365,16 +357,21 @@ extension WebSocketClient {
365357
let sslClientHandler = try NIOSSLClientHandler(context: sslContext, serverHostname: nil)
366358
try channel.pipeline.syncOperations.addHandlers(sslClientHandler)
367359
} catch {
368-
promise.fail(error)
369-
return promise.futureResult
360+
return channel.eventLoop.makeFailedFuture(error)
370361
}
371362
} catch {
372-
promise.fail(error)
373-
return promise.futureResult
363+
return channel.eventLoop.makeFailedFuture(error)
374364
}
375365
}
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()
378375
}
379376

380377
return makeChannelInitializer

0 commit comments

Comments
 (0)