1
0
Fork
You've already forked spq
0
Simple Promise Queue
  • TypeScript 100%
Find a file
2025年12月09日 02:25:50 +00:00
.github/workflows chore(deps): update actions/checkout action to v6 2025年12月09日 02:25:50 +00:00
.yarn fix: update to work with async await properly 2025年07月25日 03:20:13 +01:00
src test: update tests to be proper 2025年07月25日 03:46:51 +01:00
.gitignore feat: Re-written as typescript and added promise functions 2021年10月22日 11:55:54 +01:00
.pre-commit-config.yaml chore(ci): configure pre-commit 2023年01月11日 23:17:30 +00:00
.prettierignore feat: support adding async into the queue 2023年01月12日 02:28:04 +00:00
.prettierrc chore(ci): configure pre-commit 2023年01月11日 23:17:30 +00:00
.release-please-manifest.json chore(master): release 2.1.1 2025年07月25日 03:33:12 +01:00
.yarnrc.yml fix: update to work with async await properly 2025年07月25日 03:20:13 +01:00
CHANGELOG.md chore(master): release 2.1.1 2025年07月25日 03:33:12 +01:00
jestconfig.json feat: Re-written as typescript and added promise functions 2021年10月22日 11:55:54 +01:00
LICENSE chore: run prettier 2023年01月11日 23:17:30 +00:00
package.json chore(master): release 2.1.1 2025年07月25日 03:33:12 +01:00
README.md feat: support adding async into the queue 2023年01月12日 02:28:04 +00:00
release-please-config.json chore(ci): update building and tests 2023年01月11日 23:17:30 +00:00
renovate.json fix: updated release 2023年01月11日 23:17:30 +00:00
SECURITY.md chore(ci): update building and tests 2023年01月11日 23:17:30 +00:00
tsconfig.json feat: support adding async into the queue 2023年01月12日 02:28:04 +00:00
tslint.json feat: Re-written as typescript and added promise functions 2021年10月22日 11:55:54 +01:00
yarn.lock fix: update to work with async await properly 2025年07月25日 03:20:13 +01:00

spq (Simple Promise Queue) Build CodeQL CII Best Practices

This project exists because of an ongoing problem in projects with too many promises resolving at once. Rather than rewriting the workflow to work with scheduling library's this is designed to be a drop in replacement.

After a few lines of configuring you should be able to just replace new Promise with QueuedPromise. You can also provide custom names which will allow you to add the promises to different queues.

Example

Using promises

const firstPromise = new Promise((resolve: () => void) => {
 setTimeout(() => {
 resolve(2);
 }, 10);
});
// Imagine if there was an issue with this running at the same time or too many at once. e.g. too many open connections
const secondPromise = new Promise((resolve: () => void) => {
 resolve(3);
});
Promise.all([firstPromise, secondPromise]);

Converted to using the PromiseQueue

const { PromiseQueue } = require("spq");
const customQueue = new spq.PromiseQueue(1);
const QueuedPromise = customQueue.QueuedPromise;
const firstPromise = QueuedPromise((resolve: () => void) => {
 setTimeout(() => {
 resolve(2);
 }, 10);
});
// This won't run until the first one is fully resolved as the queue has a size of 1
const secondPromise = QueuedPromise((resolve: () => void) => {
 resolve(3);
});
Promise.all([firstPromise, secondPromise]);

You can also add async functions to the queue with the following syntax.

const firstPromise = QueuedPromise(async () => {
 await someWork();
});

PromiseQueue

Methods

pause() paused the queue but doesnt stop already running promises

resume() starts the queue and starts firing tasks.

Events

Do not change _ values directly. The event will not fire and changing to true wont trigger queueing of new tasks.

paused

Fired when the queue is paused.

resumed

Fired when the queue is resumed.

finished

Fired when the last task is finished and no more are queued.

Contributing

Please ensure that your commits are in the following style for PR's

https://www.conventionalcommits.org/en/v1.0.0/

All new methods or fixes must be covered with unit tests.

Future of this project

This was meant to be a quick projects to help queue code which otherwise overloads systems, if there are any features please feel free to open an issue and suggest possible features or ways to interact with this library.