Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jchip/item-queue
An item processing queue with Promise
https://github.com/jchip/item-queue
item pause processing promise queue resume timer watch
Last synced: 4 days ago
JSON representation
An item processing queue with Promise
- Host: GitHub
- URL: https://github.com/jchip/item-queue
- Owner: jchip
- Created: 2018-01-09T23:59:58.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-09-25T05:27:06.000Z (over 3 years ago)
- Last Synced: 2024-04-29T00:08:00.927Z (9 months ago)
- Topics: item, pause, processing, promise, queue, resume, timer, watch
- Language: TypeScript
- Size: 3.91 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# item-queue
An item processing queue using Promise.
[**API Reference**](https://jchip.github.io/item-queue/index.html)
## Features
- incrementally add items
- concurrent processing
- pause and resume processing
- automatic watch timer for long pending items## Usage
Simple Example:
```ts
import { ItemQueue } from "item-queue";async function test() {
let total = 0;const queue = new ItemQueue({
// processItem can be an async or sync function
async processItem(delay) {
await new Promise((resolve) => setTimeout(resolve, delay));
total = total + delay;
},
itemQ: [10, 20, 30, 40, 50, 60, 70, 80, 90],
concurrency: 2,
});const waiting = queue.start().wait();
queue.addItem(75); // add one item while queue in progress
queue.addItems([55, 45, 35]); // can add multiple items also
await waiting;console.log("result:", total);
}
```## Demo
More Examples:
See [sample](./samples/example1.js) for a demo usage with [visual-logger].
![item-queue demo][example1-demo-image]
[example1-demo-image]: ./samples/example1.gif
[visual-logger]: https://www.npmjs.com/package/visual-logger