Skip to content

A simple queue that handles async functions with a wait time.

Notifications You must be signed in to change notification settings

pyrsmk/dumb-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

dumb-queue

A simple and performant queue that handles async functions in order, with a wait time between each callback. It can be used as a rate limiter or to ensure asynchroneous operations are synchroneous, and not in parallel (which can be a wide source of bugs in many systems and software architectures).

Install

npm install @pyrsmk/dumb-queue

Usage

// Initialize queue with a wait time of 1000ms.
// If you don't need a wait time, you can obviously set it to `0`.
const queue = require('dumb-queue')(1000)

// The callback must return a promise so`the queue know when the task has finished.
queue.add(() => someAsyncSlowAction1())
// ...
// Further in your code.
queue.add(() => someAsyncSlowAction2())
// ...
// You can, of course, use non-async functions with the help of `async` which will
// always return a promise.
queue.add(async () => someSyncSlowAction3())

// Wait until the queue is empty.
await queue.wait()

Compatibility

Node 8+

About

A simple queue that handles async functions with a wait time.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published