https://github.com/bongofury/async-limit-queue
Little helper to create a queue of async function with limited concurrency
https://github.com/bongofury/async-limit-queue
async async-functions concurrency javascript limit limiter queue
Last synced: 4 months ago
JSON representation
Little helper to create a queue of async function with limited concurrency
- Host: GitHub
- URL: https://github.com/bongofury/async-limit-queue
- Owner: bongofury
- License: mit
- Created: 2018-05-13T13:55:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T00:50:46.000Z (over 3 years ago)
- Last Synced: 2025-10-22T12:36:54.348Z (7 months ago)
- Topics: async, async-functions, concurrency, javascript, limit, limiter, queue
- Language: JavaScript
- Size: 291 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# async-limit-queue
Dependencies-free little helper to create a queue of async function with limited concurrency.
## Description
Use this module when you have a bunch async function to be executed and want to limit the number of concurrently executed functions.
This module exports a function that creates an instance of queue with the given concurrency limit.
Use the `push` method to add (one by one) async functions to the queue. This method returns a `Promise` that is resolved when the passed async function is executed.
Items in the queue are processed _FIFO_.
## Get it
```sh
npm i async-limit-queue
yarn add async-limit-queue
```
## Usage
First import the module and create a queue...
```javascript
import createQueue from 'async-limit-queue';
// this creates a queue with concurrency limit = 7
const queue = createQueue(7);
```
... then push functions inside the queue and do something after their execution, if you want.
```javascript
const foo = async () => {/* ... */};
const bar = async () => {/* ... */};
queue.push(foo).then(
() => console.log('Function "foo" done!')
);
queue.push(bar).then(
() => console.log('Function "bar" done!')
);
```