@watchable/queue
v1.0.0
Published
In-memory MessageQueue with compile-time-immutable state.
Downloads
12
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
- immutable queue state to facilitate time-travel debugging
Read the API Reference or the reference usages below, or browse the source on Github.
Usage
// 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();
// 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
import { createQueue } from "@watchable/queue"; // for esm
const { createQueue } = require("@watchable/queue"); // for commonjs
Getting Started
Install
npm install @watchable/queue