Instance Method
onClose(_:)
A method to register closures that are invoked when the connection is closed. If the connection closed unexpectedly the closure shall be called with the underlying error. In most NIO clients this can be easily implemented by attaching to the
channel.closeFuture:func onClose(_ closure: @escaping @Sendable ((any Error)?) -> ())
Discussion
func onClose(
_ closure: @escaping @Sendable ((any Error)?) -> ()
) {
channel.closeFuture.whenComplete { _ in
closure(previousError)
}
}