Rate-limited queue
Queue tasks and throttle their execution
About
Sourced from arikw/rate-limited-queue README
Queue tasks and throttle their execute them
Installation
npm install rate-limited-queue
Usage
const createQueue = require("rate-limited-queue");
const queue = createQueue(
1000 /* time based sliding window */,
10 /* max concurrent tasks in the sliding window */,
15 /* global max concurrent tasks (Optional. Default is Infinity) */);
queue(() => { /* do something... */ });
const results = await queue([
() => { /* do another thing */ },
() => { /* and another thing */ }
]); // results = [value1, value2]
Description
This library makes sure that there are limited tasks started in a certain "sliding time window" while the rest of the tasks wait.
The algorithm
- RUNNING_TASKS = How many tasks have been started and didn't complete yet
- MAX_CONCURRENT_TASKS = How many tasks are allowed to run simultaneously
- STARTED_TASKS = How many tasks that has been started between now and X seconds ago
- AVAILABLE_SLOTS = (How many tasks are allowed to run in the sliding time window) - STARTED_TASKS
- When a task is finished, run a new task (if such exist) if the following holds true
- RUNNING_TASKS < MAX_CONCURRENT_TASKS
- AVAILABLE_SLOTS > 0
- If there're are more tasks that didn't start yet, but AVAILABLE_SLOTS is 0, do the previous step once again as soon as a slot is expected to be available
More projects
See all →2018
Flat Promise
Create a fresh new Promise with exposed 'resolve' & 'reject' callbacks available outside of its executor function
2 40.1K 391/mo
2020
Extension Page Context Runner
Run functions in page context directly from a browser extension content script
27
2020
Outlook Duplicated Items Remover
A VBA script that finds and moves duplicated items in selected outlook folders
21
2023
RX Input Layout Switcher
Alt+Shift keyboard layout switcher GNOME Shell Extension
16 9.6K
2025
Podman OpenRC Restart Policy Manager
This OpenRC init script manages the automatic startup and shutdown of Podman containers with the `restart-policy=always` on system boot or shutdown
5
2022
Express Response Hooks
Extends Express.js with response hooks
4 149.3K 5.5K/mo