moov-io / iso8583-connection

:satellite: Go-powered ISO8583 connection handler offering advanced binary framing, message interleaving, and a robust connection pool for load distribution and seamless reconnections.
Apache License 2.0
70 stars 23 forks source link

Proposal: renaming and consolidation of the connection handlers #68

Closed alovak closed 6 months ago

alovak commented 1 year ago

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 and OnClose (sync) handlers, we propose the following modifications:

  1. Rename ConnectionEstablishedHandler to OnConnected.
  2. Rename ConnectionClosedHandler to OnClosed.
  3. Invoke all OnClosed handlers regardless of how the connection was closed (by us, by the server, or due to a read/write error).

Motivation:

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):

adamdecaf commented 1 year 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?)

alovak commented 1 year ago

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
adamdecaf commented 1 year ago

I didn't mean context.Cause, but an enum referencing where the close came from.