open-index/open-npm huggingface dataset:
npm package: @olan88/q
Description: Small TypeScript promise queue with dual CJS and ESM output
Latest version: 0.0.2

# @olan88/Q

A small TypeScript promise queue package that works in both ESM and CommonJS.

## Install

```bash
npm install @olan88/Q
```

## Usage

### ESM

```ts
import { Q } from "@olan88/Q";

const queue = new Q();

queue.add(async () => {
  // runs first
});

queue.add(async () => {
  // runs after previous task is finished
});

await queue.onIdle();
```

### CommonJS

```js
const { Q } = require("@olan88/Q");

const queue = new Q();
queue.add(() => Promise.resolve("ok"));
```

## API

- `new Q()`
- `queue.add(job)`
  - Accepts a function (`() => value | Promise`) so the queue controls when it starts.
  - Returns a promise for the task result.
- `queue.size`
  - Number of queued/running tasks.
- `queue.onIdle()`
  - Resolves when all currently queued tasks are done.