- event bus systen - all components are independent - preparation for web frontend
27 lines
702 B
Python
27 lines
702 B
Python
"""What a front-end has to look like.
|
|
|
|
A service gets the bus, subscribes to state events to push outward, and emits intents
|
|
inward. Nothing else in the app knows which services exist.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Protocol, runtime_checkable
|
|
|
|
__all__ = ["Publisher", "Service"]
|
|
|
|
|
|
@runtime_checkable
|
|
class Service(Protocol):
|
|
name: str
|
|
|
|
async def run(self) -> None:
|
|
"""Long-running task. Cancelled on shutdown; may reconnect internally."""
|
|
...
|
|
|
|
|
|
class Publisher(Protocol):
|
|
"""How an entity sends something out, without knowing about the connection."""
|
|
|
|
async def publish(self, topic: str, payload: str, *, retain: bool = False) -> None: ...
|