# Queue Sandbox

Interactive demo showcasing all the ways to use queues in RivetKit. Each tab demonstrates a different queue pattern with real-time feedback.

## Getting Started

```sh
git clone https://github.com/rivet-dev/rivet.git
cd rivet/examples/queue-sandbox
npm install
npm run dev
```


## Features

- Six interactive tabs demonstrating different queue patterns
- Real-time state updates via broadcasts and polling
- Progress indicators for long-running operations
- Multi-queue priority handling

## Implementation

This example demonstrates six queue patterns:

### Send

Basic queue messaging where the client sends messages to an actor queue, and the actor manually receives them.

See [`src/actors/sender.ts`](https://github.com/rivet-dev/rivet/tree/main/examples/queue-sandbox/src/actors/sender.ts).

### Multi-Queue

Listen to multiple named queues (high, normal, low priority) simultaneously using `for await (const m of c.queue.iter({ names: [...] }))`.

See [`src/actors/multi-queue.ts`](https://github.com/rivet-dev/rivet/tree/main/examples/queue-sandbox/src/actors/multi-queue.ts).

### Timeout

Demonstrate the timeout option when waiting for messages. Shows countdown timer and handles both successful receives and timeouts.

See [`src/actors/timeout.ts`](https://github.com/rivet-dev/rivet/tree/main/examples/queue-sandbox/src/actors/timeout.ts).

### Worker

Use the `run` handler to continuously consume queue messages in a `for await` loop.

See [`src/actors/worker.ts`](https://github.com/rivet-dev/rivet/tree/main/examples/queue-sandbox/src/actors/worker.ts).

### Self-Send

Actor sends messages to its own queue using the inline client pattern (`c.client<typeof registry>()`).

See [`src/actors/self-sender.ts`](https://github.com/rivet-dev/rivet/tree/main/examples/queue-sandbox/src/actors/self-sender.ts).

### Keep Awake

Consume queue messages and perform long-running tasks wrapped in `c.keepAwake()` to prevent the actor from sleeping during processing.

See [`src/actors/keep-awake.ts`](https://github.com/rivet-dev/rivet/tree/main/examples/queue-sandbox/src/actors/keep-awake.ts).

## Resources

Read more about [queues](/docs/actors/queues), [run handlers](/docs/actors/run), and [state](/docs/actors/state).

## License

MIT
