> ## Documentation Index
> Fetch the complete documentation index at: https://torqpy.itsdote.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Shared bus

> Thin typed values and events on the logical clock — not a PySim capacity Store.

`Shared` is a thin typed blackboard + signal bus stamped at logical `now`. Use it across audio / MIDI / sim / lab shreds.

> [!WARNING]
>
> **Not** a PySim / SimPy capacity `Store` or `Resource`. No slots, no get/put queues, no preemption.

```python theme={null}
from torq import Clock, Shared, ms, spork
```

## Construction

| Member | Meaning |
| - | - |
| `Shared(clock)` / `clock.shared()` | Bus bound to one clock |
| `.declare(key, typ)` | Optional `isinstance` gate for later `.set` |
| `.set(key, value)` / `.get` / `.has` / `.stamp` / `.entry` | Latest-wins value + `Time` of last write |
| `.wait(key)` | Park until key exists; if already set, continue now → value |
| `.changed(key)` | Park until the **next** `.set` on key → value |
| `.emit(topic, payload=None)` | Stamp a `SharedEvent` at `now`; wake `.once` waiters |
| `.once(topic)` | Park until next emit → `SharedEvent` |
| `.values()` / `.history()` / `.clear()` | Snapshot; emit log; drop values+log (live waiters stay) |

`yield from bus.wait(...)` / `await bus.once(...)` (and `.changed`) mirror `Join`: same-clock only; `unspork` unregisters waiters; wake is at the tail of current `now`.

## Example

```python theme={null}
clock = Clock()
bus = clock.shared()  # or Shared(clock)

def junnu():
    yield 100 * ms
    bus.set("cue", "go")
    bus.emit("hit", 60)

def laddu():
    cue = yield from bus.wait("cue")
    ev = yield from bus.once("hit")
    assert cue == "go" and ev.payload == 60

clock.spork(junnu())
clock.spork(laddu())
clock.run()
```

## Types

| Type | Role |
| - | - |
| `SharedValue` | Latest value + stamp |
| `SharedEvent` | Emitted topic payload + stamp |
| `SharedWait` | Park token (like `Join`) |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.