diff options
| author | cjd24 | 2018-04-25 06:41:56 +0100 |
|---|---|---|
| committer | cjd24 | 2018-04-25 06:41:56 +0100 |
| commit | f36deb0245881d8442c31e16572c67e58bb7c451 (patch) | |
| tree | 8e3cc52fe8b8a896be28ff1453ebe5dd82e39b24 /src/ppq/index.js | |
| parent | Edit promise queue to return promises itself (diff) | |
| download | medicine-f36deb0245881d8442c31e16572c67e58bb7c451.tar.gz medicine-f36deb0245881d8442c31e16572c67e58bb7c451.zip | |
Fixing lots of CZI integration things, to prep for server deployment for JH demo
Diffstat (limited to 'src/ppq/index.js')
| -rw-r--r-- | src/ppq/index.js | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/ppq/index.js b/src/ppq/index.js index 37856d0..ec2f188 100644 --- a/src/ppq/index.js +++ b/src/ppq/index.js @@ -1,14 +1,17 @@ class PromisePriorityQueue { - construtor(concurrent, least) { + + constructor(concurrent, least) { this.least = least || 10; - this.concurrent = concurrent || 50; + this.concurrent = concurrent || 2; this.running = 0; this.queues = []; - for (let i = 1; i <= this.least; ++i) { + for (let i = 0; i < this.least; ++i) { this.queues[i] = []; } + + this.size = 0; } configure(config) { @@ -16,17 +19,29 @@ class PromisePriorityQueue { if (config.concurrent) this.concurrent = config.concurrent; } - enqueue(i, p) { + // enqueue(i, p, t, ...args) { + // return p.bind(t)(...args); + // } + + enqueue(i, p, t, ...argv) { + this.size++; return new Promise((res, rej) => { - q[i].push([p, res, rej]); + this.queues[i-1].push( + [ + p.bind(t, ...argv), + res, + rej + ] + ); this.run(); }); }; dequeue() { for (let i = 0; i < this.least; ++i) { - if (q[i][0] !== undefined) { - return q[i].shift; + if (this.queues[i][0] !== undefined) { + this.size--; + return this.queues[i].shift(); } } return null; @@ -35,7 +50,7 @@ class PromisePriorityQueue { async run() { if (this.running < this.concurrent) { let x; - while (this.dequeue()) { + while (x = this.dequeue()) { await x[0]().then(x[1], x[2]); } } |
