@@ -38,7 +38,7 @@ function Connection(options = {}) {
3838 , connection = { send, end, destroy }
3939
4040 const socket = postgresSocket ( options , {
41- ready : ( ) => socket . write ( frontend . connect ( options ) ) ,
41+ ready,
4242 data,
4343 error,
4444 close
@@ -114,26 +114,26 @@ function Connection(options = {}) {
114114 }
115115
116116 function send ( query , { sig, str, args = [ ] } ) {
117- query . str = str
118- query . args = args
119- query . result = [ ]
120- query . result . count = null
121- idle_timeout && clearTimeout ( timer )
122-
123- typeof options . debug === 'function' && options . debug ( id , str , args )
124- const buffer = query . simple
125- ? simple ( str , query )
126- : sig in statements
127- ? prepared ( statements [ sig ] , args , query )
128- : prepare ( sig , str , args , query )
129-
130- ready
131- ? ( backend . query = query , ready = false )
132- : queries . push ( query )
133-
134- open
135- ? socket . write ( buffer )
136- : ( messages . push ( buffer ) , connect ( ) )
117+ query . str = str
118+ query . args = args
119+ query . result = [ ]
120+ query . result . count = null
121+ idle_timeout && clearTimeout ( timer )
122+
123+ typeof options . debug === 'function' && options . debug ( id , str , args )
124+ const buffer = query . simple
125+ ? simple ( str , query )
126+ : sig in statements
127+ ? prepared ( statements [ sig ] , args , query )
128+ : prepare ( sig , str , args , query )
129+
130+ ready
131+ ? ( backend . query = query , ready = false )
132+ : queries . push ( query )
133+
134+ open
135+ ? socket . write ( buffer )
136+ : ( messages . push ( buffer ) , connect ( ) )
137137 }
138138
139139 function connect ( ) {
@@ -244,7 +244,6 @@ function Connection(options = {}) {
244244function postgresSocket ( options , {
245245 error,
246246 close,
247- ready,
248247 data
249248} ) {
250249 let socket
@@ -295,6 +294,14 @@ function postgresSocket(options, {
295294 socket . once ( 'close' , onclose )
296295 }
297296
297+ function ready ( ) {
298+ try {
299+ socket . write ( frontend . connect ( options ) )
300+ } catch ( e ) {
301+ error ( e )
302+ }
303+ }
304+
298305 const x = {
299306 write : x => {
300307 buffer = buffer ? Buffer . concat ( [ buffer , x ] ) : Buffer . from ( x )
0 commit comments