Closed alovak closed 6 months ago
Would you pass a cause to each handler so the receiver could ignore certain conditions? (e.g. ignore when the Pool closes a connection?)
I'm not sure @adamdecaf. From what I see from the production code, there is no need for such. But I don't also know how to do it and maybe how to use it later (the use case is not clear to me). Can you show me an example?
Is it something like
select {
case <-ctx.Done():
log.WithError(context.Cause(ctx)).Warn("canceled")
return err
I didn't mean context.Cause
, but an enum referencing where the close came from.
Background:
In an effort to simplify our interface and offer a more intuitive experience to developers, we are proposing a renaming and consolidation of our connection handlers.
Proposed Changes:
In addition to the existing
OnConnect
andOnClose
(sync) handlers, we propose the following modifications:Motivation:
Consistent Naming: The new naming convention is both intuitive and in line with common practices, providing a more streamlined experience for developers.
Unified Closure Handling with
OnClosed
:OnClosed
handlers would only be triggered when a connection was closed by the server or due to read/write errors. This allowed connection pools to handle unexpected disconnects and initiate reconnections.connection.Close
, the handlers set up by the connection pool are not executed and it wouldn't initiate a reconnection.OnClosed
handlers are triggered regardless of the cause of closure, we address this oversight. This provides more consistent behavior, ensuring that any necessary cleanup or reconnection logic is always executed. It makes the connection's lifecycle more predictable, offering more control and flexibility to developers.This revision aims to eliminate unexpected behaviors and provide a more consistent and reliable connection management experience.
Changes, except 3rd point, will be backward compatible, we will support old names for some time.
Changed Callbacks
OnConnect (sync):
Connect
method will return that error, preventing the connection from being established.OnConnected (async):
OnClose (sync):
Close
method will return that error, and the connection will not be closed.OnClosed (async):