# u-queue

> Micro promise-based queues

Latest version **1.4.0** (published 2026-04-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install u-queue
pnpm add u-queue
yarn add u-queue
bun add u-queue
```

## Health

**Score 55/100 (C)** — status: active.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.4.0 |
| Published | 2026-04-30 |
| First published | 2019-05-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Vladimir Meremyanin |
| Maintainers | vstiff |
| Keywords | promise, queue |

## Links

- npm: https://www.npmjs.com/package/u-queue
- Repository: https://github.com/stiff/u-queue
- Homepage: https://github.com/stiff/u-queue#readme
- Issues: https://github.com/stiff/u-queue/issues
- npm.io page: https://npm.io/package/u-queue

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 1.4.0 (latest) — 2026-04-30
- 1.3.0 — 2024-12-12
- 1.1.0 — 2019-05-06
- 1.0.0 — 2019-05-06

## README

# µQueue

Small collection of promise-based queues used in several projects.

## Installation

```npm install --save u-queue```

## Usage

```js
const { queueFactory, singleInstance, sleep, throttlingQueueFactory } = require('u-queue');
```

### queueFactory

Creates simplest queue, that invokes promises one after another.

```js
const queue = queueFactory();

const longProcesses = [
    queue(() => sleep(1500).then(() => 1)),
    queue(() => sleep(1000).then(() => 2)),
    queue(() => sleep(500).then(() => 3)),
];

Promise.all(longProcesses).then(console.log);
// Promise {<pending>}
// => [1, 2, 3]
```

### throttlingQueueFactory

Same as `queueFactory` but adds delay after each promise is resolved.

```js
const queue = throttlingQueueFactory({ delay: 1000 });

queue(() => console.log(new Date()));
queue(() => console.log(new Date()));
queue(() => console.log(new Date()));

// Promise {<pending>}
// 11:16:27
// 11:16:28
// 11:16:29
```

### singleInstance

Decorator around async function to run it only once at a time and reuse results for subsequent calls while it's running even if invoked with different arguments.

```js
let start = Date.now();
const f = singleInstance(async (tag) => {
  await sleep(1000);
  return [ tag, Date.now() - start ];
});
console.log(await Promise.all([f(1), f(2), f(3), f(4)]));
// [ [ 1, 1001 ], [ 1, 1001 ], [ 1, 1001 ], [ 1, 1001 ] ]
console.log(await Promise.all([f(1), f(2), f(3), f(4)]));
// [ [ 1, 2002 ], [ 1, 2002 ], [ 1, 2002 ], [ 1, 2002 ] ]
```

### sleep

Creates promise that is resolved after specified milliseconds. Used internally by `throttlingQueueFactory`, but may be useful somewhere else as well.

```js
sleep(3141).then(console.log);
```

---
_Source: https://npm.io/package/u-queue · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
