Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/minimal-queue
Minimal FIFO queue implementation to be used for simple concurrency limiting scenarios.
https://github.com/thlorenz/minimal-queue
Last synced: 26 days ago
JSON representation
Minimal FIFO queue implementation to be used for simple concurrency limiting scenarios.
- Host: GitHub
- URL: https://github.com/thlorenz/minimal-queue
- Owner: thlorenz
- License: other
- Created: 2012-06-24T03:33:42.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-09-25T01:07:06.000Z (over 12 years ago)
- Last Synced: 2024-11-23T01:53:23.105Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 104 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# minimal-queue
Minimal FIFO queue implementation to be used for simple concurrency limiting scenarios.
# Installation
`npm install minimal-queue`
# Usage
Create a queue by passing a worker function that will be processed each time some arguments are enqueued.
Optionally limit concurrency (default is 50) in order to limit number of jobs allowed to run at the same time.## Example
```javascript
var queue = require('minimal-queue')
, myQueue = queue.up (function (job) {
var that = this;
console.log('Starting ', job);
setTimeout(function () {
console.log('Processed %s. Calling done now to allow more jobs to run.', job);
that.done();
}, 200);
})
;myQueue.concurrency = 2;
myQueue.allDone = function () { console.log('Yay, we are now out of jobs!'); };myQueue.enqueue('first job');
myQueue.enqueue('second job');
myQueue.enqueue('third job');```
Running the above produces the following output:Starting first job
Starting second job
Processed first job. Calling done now to allow more jobs to run.
Starting third job
Processed second job. Calling done now to allow more jobs to run.
Processed third job. Calling done now to allow more jobs to run.
Yay, we are now out of jobs!