Skip to content

Little helper to create a queue of async function with limited concurrency

License

Notifications You must be signed in to change notification settings

bongofury/async-limit-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

npm i async-limit-queue

yarn add async-limit-queue

Usage

First import the module and create a queue...

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.

const foo = async () => {/* ... */};
const bar = async () => {/* ... */};

queue.push(foo).then(
  () => console.log('Function "foo" done!')
);

queue.push(bar).then(
  () => console.log('Function "bar" done!')
);