Stage 07.4.3.2 — price polling, event bus and UI throttling
This commit is contained in:
28
app/src/core/event_bus.py
Normal file
28
app/src/core/event_bus.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# app/src/core/event_bus.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
class EventBus:
|
||||
_version: int = 0
|
||||
_last_event_type: str | None = None
|
||||
_last_payload: dict[str, Any] = {}
|
||||
|
||||
# зафиксировать важное событие системы
|
||||
@classmethod
|
||||
def emit(cls, event_type: str, payload: dict[str, Any] | None = None) -> None:
|
||||
cls._version += 1
|
||||
cls._last_event_type = event_type
|
||||
cls._last_payload = payload or {}
|
||||
|
||||
# текущая версия событий
|
||||
@classmethod
|
||||
def version(cls) -> int:
|
||||
return cls._version
|
||||
|
||||
# последнее событие
|
||||
@classmethod
|
||||
def last_event(cls) -> tuple[str | None, dict[str, Any]]:
|
||||
return cls._last_event_type, dict(cls._last_payload)
|
||||
Reference in New Issue
Block a user