brianc/node-postgres — pull request #662 by jusou (2014-10-20 03:04:10+00:00)
Title: Submit queries immediately rather that waiting for ReadyForQuery, when possible

This pull request causes node-postgres to send queries immediately, unless a copyFrom request has been sent and has not completed.

This fixes the current disastrous state of this library that always waits for query results before submitting the next query, resulting in O(n) rather than O(1) latency for n queries sent without waiting by a client.

API additions:
- Client.sendImmediately can be set to false to restore the previous behavior
- Query.blocking can be set to block sending any further query until this query is completed

Internal additions:
- Client.handshakeDone is set if any ReadyForQuery has been seen
- Client.sentQueryQuery is the queue of queries that have been sent on the wire

If you would prefer to keep the old behavior by default (not recommended, since it means being broken by default), you can remove the "this.sendImmediately = true;" line.