MCPcopy Create free account
hub / github.com/porsager/postgres / reserve

Function reserve

cjs/src/index.js:203–232  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

201 }
202
203 async function reserve() {
204 const queue = Queue()
205 const c = open.length
206 ? open.shift()
207 : await new Promise((resolve, reject) => {
208 const query = { reserve: resolve, reject }
209 queries.push(query)
210 closed.length && connect(closed.shift(), query)
211 })
212
213 move(c, reserved)
214 c.reserved = () => queue.length
215 ? c.execute(queue.shift())
216 : move(c, reserved)
217 c.reserved.release = true
218
219 const sql = Sql(handler)
220 sql.release = () => {
221 c.reserved = null
222 onopen(c)
223 }
224
225 return sql
226
227 function handler(q) {
228 c.queue === full
229 ? queue.push(q)
230 : c.execute(q) || move(c, full)
231 }
232 }
233
234 async function begin(options, fn) {
235 !fn && (fn = options, options = '')

Callers

nothing calls this directly

Calls 6

QueueFunction · 0.70
connectFunction · 0.70
moveFunction · 0.70
SqlFunction · 0.70
onopenFunction · 0.70
executeMethod · 0.65

Tested by

no test coverage detected