Skip to content

Commit c1ce6ae

Browse files
committed
Proper open/ready separation
1 parent 730df2c commit c1ce6ae

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/connection.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function Connection(options = {}) {
2424
let timer
2525
let statement_id = 1
2626
let ended
27+
let open = false
2728
let ready = false
2829
let statements = {}
2930

@@ -94,11 +95,11 @@ function Connection(options = {}) {
9495
? prepared(statements[sig], args, query)
9596
: prepare(sig, str, args, query)
9697

97-
backend.query || !ready
98-
? queries.push(query)
99-
: (backend.query = query)
100-
10198
ready
99+
? (backend.query = query, ready = false)
100+
: queries.push(query)
101+
102+
open
102103
? socket.write(buffer)
103104
: (messages.push(buffer), socket.connect())
104105
}
@@ -137,13 +138,14 @@ function Connection(options = {}) {
137138
if (queries.length === 0 && ended)
138139
return ended()
139140

140-
if (!ready) {
141+
if (!open) {
141142
messages.forEach(socket.write)
142143
messages = []
143-
ready = true
144+
open = true
144145
}
145146

146147
backend.query = queries.shift()
148+
ready = !backend.query
147149
}
148150

149151
function data(x) {
@@ -164,7 +166,7 @@ function Connection(options = {}) {
164166
function close() {
165167
error(errors.connection('CLOSED', options))
166168
statements = {}
167-
ready = false
169+
open = ready = false
168170
}
169171

170172
/* c8 ignore next */

0 commit comments

Comments
 (0)