# @watchable/queue

> In-memory MessageQueue with compile-time-immutable state.

Latest version **1.0.0** (published 2024-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @watchable/queue
pnpm add @watchable/queue
yarn add @watchable/queue
bun add @watchable/queue
```

## Health

**Score 40/100 (D)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-04-01 |
| First published | 2023-04-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Cefn Hoile |
| Maintainers | cefn |

## Links

- npm: https://www.npmjs.com/package/@watchable/queue
- Repository: https://github.com/cefn/watchable
- Homepage: https://github.com/cefn/watchable/tree/main/packages/queue#readme
- Issues: https://github.com/cefn/watchable/issues?q=is%3Aissue+is%3Aopen+label%3Aqueue
- npm.io page: https://npm.io/package/@watchable/queue

## Recent versions

- 1.0.0 (latest) — 2024-04-01
- 0.9.0-alpha.1 (alpha) — 2023-04-30
- 1.0.0-alpha.5 — 2023-07-04
- 0.9.0-alpha.4 — 2023-07-04
- 0.9.0-alpha.3 — 2023-05-03
- 0.9.0-alpha.2 — 2023-04-30

## README

## Minimal in-memory message queue

A Typescript queue implementation with...

- a Promise-oriented, Generic API to build your own event loops
- queue limits to facilitate [backpressure](https://medium.com/@jayphelps/backpressure-explained-the-flow-of-data-through-software-2350b3e77ce7)
- immutable queue state to facilitate [time-travel debugging](https://medium.com/replay-io/introduction-to-time-travel-debugging-a02786c5c0d9)

Read the [API Reference](https://watchable.dev/api/modules/_watchable_queue.html) or the reference usages below, or [browse the source on Github](https://github.com/cefn/watchable/tree/main/packages/queue).

## Usage

```typescript
// Create a queue that accepts any values
const queue = createQueue();

// put an event in the queue
queue.send({
  kind: "move",
  x: 200,
  y: 200,
});

// block until next event is available
const action = await queue.receive();
```

```typescript
// define an event type
interface Coordinate {
  x: number;
  y: number;
}

// Create a queue for typed events
const typedQueue = createQueue<Coordinate>();

// block until next event is available
const { x, y } = await queue.receive();
```

### Import OR Require

```javascript
import { createQueue } from "@watchable/queue"; // for esm
const { createQueue } = require("@watchable/queue"); // for commonjs
```

## Getting Started

### Install

```zsh
npm install @watchable/queue
```

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