-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixes #454. Added DisconnectedErrCB to client #462
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution! I think it looks good, the only comments I would have are about the doc of the disconnected handlers.
nats.go
Outdated
@@ -266,8 +269,15 @@ type Options struct { | |||
|
|||
// DisconnectedCB sets the disconnected handler that is called | |||
// whenever the connection is disconnected. | |||
// Will not be called if DisconnectedErrCB was initiated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be: Will not be called if DisconnectedErrCB is set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, fixed docs
nats.go
Outdated
@@ -266,8 +269,15 @@ type Options struct { | |||
|
|||
// DisconnectedCB sets the disconnected handler that is called | |||
// whenever the connection is disconnected. | |||
// Will not be called if DisconnectedErrCB was initiated. | |||
// DEPRECATED. use DisconnectedErrCB which passes initial err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which passes error that caused the disconnect event
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, fixed docs
nats.go
Outdated
DisconnectedCB ConnHandler | ||
|
||
// DisconnectedErrCB sets the disconnected error handler that is called | ||
// whenever the connection is disconnected. | ||
// DisconnectedCB will not be called if DisconnectedErrCB was initiated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DisconnectedCB will not be called if DisconnectedErrCB is set
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, fixed docs
nats.go
Outdated
nc.ach.push(func() { nc.Opts.DisconnectedCB(nc) }) | ||
if nc.conn != nil { | ||
if nc.Opts.DisconnectedErrCB != nil { | ||
nc.ach.push(func() { nc.Opts.DisconnectedErrCB(nc, ErrConnectionClosed) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if maybe here we should use nil
for the error instead of ErrConnectionClosed
? That would mean that when calling nc.Close()
, the disconnected callback is called but there is no error since it was called by the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. We should then add this to the "doc" of DisconnectedErrCB that it is possible to get nil
as an error, one case would be when the user closes the connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @wallyqs , thanks for review. Found possible missed case with err passing:
nats.go:1438 where we trying to initialize connected connection and got an err as result, if so we close connection with status DISCONNECTED
. I think we should pass acquired error to new callback too, adding err
as param to close()
method? WDYT?
Adding err as param to close()
will fix pointed issue when user closes connection, we will pass nil here with status CLOSED
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that sounds good (thanks!)
nats.go
Outdated
nc.ach.push(func() { nc.Opts.DisconnectedCB(nc) }) | ||
if nc.conn != nil { | ||
if nc.Opts.DisconnectedErrCB != nil { | ||
nc.ach.push(func() { nc.Opts.DisconnectedErrCB(nc, ErrConnectionClosed) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. We should then add this to the "doc" of DisconnectedErrCB that it is possible to get nil
as an error, one case would be when the user closes the connection.
…ted connection failed to initialize
@kozlovic @wallyqs Thanks for fast review! I've updated docs and added logic with proper err passing for close/disconnect status. Looks like it could be merged. One thing i want to mention that i noticed blinking test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I would like a second pass on comments. After that I think we can merge. Thanks again for the contribution!
@mkorolyov I was getting ready to do a release and noticed that we missed some deprecated statements, but then I am having second thoughts. I wonder if we should not have named the handler |
@kozlovic i can rename myself in PR, have some time at the moment :) |
Ok great! |
No description provided.