File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -181,6 +181,8 @@ function postgresSocket(options, {
181
181
} ) {
182
182
let socket
183
183
let closed = true
184
+ let next = null
185
+ let buffer
184
186
185
187
function onclose ( ) {
186
188
socket . removeListener ( 'data' , data )
@@ -227,7 +229,12 @@ function postgresSocket(options, {
227
229
228
230
const x = {
229
231
ready : false ,
230
- write : x => socket . write ( x ) ,
232
+ write : x => {
233
+ buffer = buffer ? Buffer . concat ( [ buffer , x ] ) : Buffer . from ( x )
234
+ if ( buffer . length >= 1024 )
235
+ return write ( )
236
+ next === null && ( next = setImmediate ( write ) )
237
+ } ,
231
238
destroy : ( ) => {
232
239
socket && socket . destroy ( )
233
240
return Promise . resolve ( )
@@ -238,6 +245,12 @@ function postgresSocket(options, {
238
245
connect
239
246
}
240
247
248
+ function write ( ) {
249
+ socket . write ( buffer )
250
+ next !== null && clearImmediate ( next )
251
+ buffer = next = null
252
+ }
253
+
241
254
/* c8 ignore next */
242
255
return x
243
256
}
You can’t perform that action at this time.
0 commit comments