-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add 'drain' event to Protocol and Connection. #272
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
Conversation
This event is emitted by the Protocol (and re-emitted by the Connection) when all sequences have been dequeued.
I've kept this pretty minimal, but I was wondering if you think we should suppress 'drain' events after |
@@ -15,6 +15,7 @@ function Connection(options) { | |||
this._socket = options.socket; | |||
this._protocol = new Protocol({config: this.config}); | |||
this._connectCalled = false; | |||
this._protocol.on('drain', this.emit.bind(this, 'drain')); |
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.
Could you attach this callback inside the Connection#connect
method? As a general rule, my constructors are kept as dump as possible, and this is where all the other Protocol event handlers are defined.
Thanks. Looks good to me, and so does the test. Could you address my comment above? Then I'll merge this. |
Oh wait, also adding some docs for this would be great. |
For consistency with other event handlers
I'm not 100% sold on my documentation update, but the Readme doesn't enumerate events anywhere so I wasn't sure how else to integrate it. |
Can you update this? I can refactor the code if you prefer. This drain event is requested by multiple users (on multiple issues). The documentation could be simpler, like: Idle ConnectionsConnections emit con.query("....");
con.query("....");
con.query("....");
con.on("drain", function () {
console.log("all done! connection is now idle");
}); |
I definitely prefer the elided documentation example, but I'm no longer convinced this feature is even necessary. |
This event is emitted by the Protocol (and re-emitted by the Connection) when
all sequences have been dequeued.
See #271 for the initial discussion for this change.