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

Function Queue

cjs/src/queue.js:3–31  ·  view source on GitHub ↗
(initial = [])

Source from the content-addressed store, hash-verified

1module.exports = Queue
2
3function Queue(initial = []) {
4 let xs = initial.slice()
5 let index = 0
6
7 return {
8 get length() {
9 return xs.length - index
10 },
11 remove: (x) => {
12 const index = xs.indexOf(x)
13 return index === -1
14 ? null
15 : (xs.splice(index, 1), x)
16 },
17 push: (x) => (xs.push(x), x),
18 shift: () => {
19 const out = xs[index++]
20
21 if (index === xs.length) {
22 index = 0
23 xs = []
24 } else {
25 xs[index - 1] = undefined
26 }
27
28 return out
29 }
30 }
31}

Callers 4

PostgresFunction · 0.70
reserveFunction · 0.70
beginFunction · 0.70
ConnectionFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected