Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

grncdr
Copy link
Contributor

@grncdr grncdr commented Aug 10, 2012

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.

This event is emitted by the Protocol (and re-emitted by the Connection) when
all sequences have been dequeued.
@grncdr
Copy link
Contributor Author

grncdr commented Aug 10, 2012

I've kept this pretty minimal, but I was wondering if you think we should suppress 'drain' events after Quit sequences?

@@ -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'));
Copy link
Collaborator

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.

@felixge
Copy link
Collaborator

felixge commented Aug 15, 2012

Thanks. Looks good to me, and so does the test. Could you address my comment above? Then I'll merge this.

@felixge
Copy link
Collaborator

felixge commented Aug 15, 2012

Oh wait, also adding some docs for this would be great.

@travisbot
Copy link

This pull request passes (merged e0d71b0 into f346077).

@grncdr
Copy link
Contributor Author

grncdr commented Aug 15, 2012

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.

@dresende
Copy link
Collaborator

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 Connections

Connections emit 'drain' events after they have finished all queued queries (including query callbacks). This event could be used to detect idle connections:

con.query("....");
con.query("....");
con.query("....");

con.on("drain", function () {
  console.log("all done! connection is now idle");
});

@grncdr
Copy link
Contributor Author

grncdr commented Oct 31, 2012

I definitely prefer the elided documentation example, but I'm no longer convinced this feature is even necessary.

@dresende dresende closed this in ed2091a Nov 2, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants