> ## 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.

# Clock

> Logical scheduler: now, spork, run, advance, and context binding.

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

## Construction

| Member | Meaning |
| - | - |
| `Clock(sample_rate=48000)` | Logical scheduler |
| `.now` | Current `Time` |
| `.samp` / `.second` / `.ms` / `.minute` | Rate-aware units |
| `.spork(gen_or_async)` | Start a shred (creation order = tie-break); returns `Shred` |
| `.run()` / `.run(until=Time)` | Drain shreds |
| `.advance(dur)` | Move `now` forward, run due shreds |
| `.next_wake` | Next scheduled wake or `None` |
| context manager | Binds module `spork` / `now` via contextvars |
| `.unspork(shred)` | Cancel a shred (see [Shreds](https://torqpy.itsdote.tech/reference/shreds.md)) |
| `.shreds()` | Machine-local `ShredGroup` |
| `.shared()` | Thin `Shared` bus on this clock |

```python theme={null}
from torq import Clock, second

clock = Clock()
log = []

def voice(name):
    for _ in range(2):
        log.append((name, clock.now))
        yield second

clock.spork(voice("junnu"))
clock.spork(voice("Laddu"))
clock.run()
# junnu then Laddu at each wake — creation order wins
```

## Context binding

Inside `with clock:`, module helpers (`spork`, `now`, …) target that clock:

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

clock = Clock()
hits = []

async def metro():
    hits.append(now())
    await (~(100 * ms))

with clock:
    spork(metro)
clock.run()
```

## Native clock

`torq.native_clock` exposes a C++-backed clock matching Python semantics when `torq._vm` is built. Same public timing ideas; see tests under `torq/tests/test_native.py`.


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