Repository navigation
en guides subscriptions
import asyncio
from toffee import Execution, RisingEdge, on
snapshots = asyncio.Queue()
# clock 与 payload 是项目已经绑定的时钟和 Bundle。
@on(RisingEdge(clock), capture=lambda event: (event.tick, payload.sample()))
async def observe(snapshot):
snapshots.put_nowait(snapshot)
async with Execution(backend) as execution:
execution.subscribe(observe.bind())
tick, value = await snapshots.get()
# 消费命中 phase 保存的不可变 BundleValue。
assert value == expected
await trigger creates a one-shot registration. @on uses the same compilation path but rearms after matches
and delivers results through a handler queue.
-
losslessfails explicitly when its queue fills. -
latestdrops old queued items to retain recent values. -
capture=must synchronously create an immutable snapshot at the matching phase. - The handler must be
async def.
A handler receives the captured value, or XEvent when capture is omitted. Handlers can run later;
rereading a live signal does not recover the original sample.
The example's trigger is already bound, so .bind() takes no arguments.
A subscription declared against a trigger factory, such as @on(handshake), instead uses .bind(dut).
Execution cancels and reclaims subscriptions on exit.
Run the pure-Python example:
python3 examples/triggers/subscription.py
Use a Monitor when tests need await recv() or response checking.
Use @on for component handlers that persistently process samples or state events, without blocking the event loop.
Capture occurs at the match phase even if the handler is slow. A lossless overflow raises
SubscriptionOverflowError; capture or handler exceptions fail Execution, which still reclaims tasks.
The decorator returns XSubscriptionSpec; bind returns BoundSubscriptionSpec; Execution.subscribe returns
an active Subscription. Components can cancel it early with execution.reactor.cancel_subscription(subscription).
Ordinary tests rely on Execution cleanup.
Value modes remain enter/each_sample/change: persistent rearming does not convert enter into a notification every high cycle.
内容由 CI 自动同步;请编辑主仓库文档。 Automatically synced by CI; edit the source documentation.
- 首页
- 教程
- 操作指南
- 参考
- 原理说明
- Home
-
Tutorials
- Learning path
- 0. Prepare your environment
- 1. Your first PASS and FAIL
- 2. Inputs and clocks
- 3. More cases and boundaries
- 4. Extract a Driver
- 5. Delayed output and a Monitor
- 6. Assemble an Agent
- 7. Models and the test environment
- 8. Pipelines, batches, and cancellation
- 9. Understand failures
- 10. Functional coverage
- Optional: out-of-order responses
- Optional: native clocks and project DUTs
-
How-to guides
- Find your task
- Simulation and events
- Verification components
- Coverage and regressions
- Migration and maintenance
- Runnable examples
- Reference
- Explanation