Skip to content
This repository was archived by the owner on Nov 23, 2022. It is now read-only.

Commit b4f68ba

Browse files
committed
update readme
1 parent f16e39b commit b4f68ba

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
# queue-manager
2+
23
A wrapper over [async](https://caolan.github.io/async/v3/docs.html) queue helpful in managing the queue length
4+
5+
### Usage example
6+
7+
```javascript
8+
// inputArray of huge length (approx 1000 or more)
9+
const lowWaterMark = 40; // whatever you want it to be
10+
const highWaterMark = 100; // whatever you want it to be
11+
12+
function main(inputArray) {
13+
const queue = async.queue(worker, 20);
14+
async function worker(input, cb) {
15+
console.log("queue length -->", queue.length());
16+
if (queue.length() <= lowWaterMark) queueManager.resume();
17+
await doSomething(input);
18+
return cb();
19+
}
20+
const queueManager = new QueueManager(queue);
21+
for (const input of inputArray) {
22+
if (queue.length() >= highWaterMark) await queueManager.pause(); // pauses the loop till queue length has decreased below low watermark
23+
queue.push(input);
24+
}
25+
}
26+
```

0 commit comments

Comments
 (0)