Publisher module
Defines the Publisher
, the central data bus for the dashboard.
Enables creation and management of named data streams, allowing consumers to subscribe to value updates or periodic “clock” ticks.
Classes
Publisher
Manages data streams and subscriptions.
- class publisher.Publisher
Core data bus for the dashboard.
Holds named streams. Consumers subscribe to streams for data updates or periodic ticks.
Methods
- __init__()
Initializes:
streams: dict mapping stream names to subscriber lists
stream_update_callbacks: callbacks for new streams
ticks: tick counter
clock_callbacks: periodic tick callbacks
- register_stream_callback(cb)
Register a callback for stream set changes. Callback receives a sorted list of stream names.
- get_all_streams()
Return a sorted list of all stream names.
- subscribe(stream, callback)
Subscribe callback to updates on stream. On update(stream, payload), calls callback(stream, payload).
- unsubscribe_from_all(callback)
Unsubscribe callback from all streams and clock subscriptions.
- update(stream, payload)
Publish payload to stream. Ensures stream exists, then notifies all subscribers.
- subscribe_clock(interval, callback)
Subscribe callback to periodic ticks. Calls callback(ticks) every interval calls to update_clock().
- update_clock()
Increment tick counter and invoke matching clock callbacks.
- ensure_exists(stream)
Ensure stream is registered. If new, creates it and notifies all stream update callbacks.
Module-level variables
publisher: Default
Publisher
instance.