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

Function reserve

cf/src/index.js:204–233  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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