walletpress/backend/core/event_bus.py
cryptorugmunch e13bd4d774
Some checks are pending
CI / lint (push) Waiting to run
CI / test (push) Waiting to run
CI / security (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / license (push) Waiting to run
CI / ai-review (push) Waiting to run
docs: apply fleet-template (16-artifact scaffold)
Adds missing standard artifacts:
- README.md (if missing)
- AGENTS.md (AI agent contract)
- PLAN.md (current sprint)
- STATUS.md (where we are)
- DEVELOPMENT.md (dev workflow)
- DEPLOYMENT.md (deploy procedure)
- TESTING.md (test strategy)
- DECISIONS.md (ADR index + templates)
- .github/CODEOWNERS
- .github/workflows/ci.yml

Preserves all existing artifacts.

Refs: RugMunchMedia/fleet-template
2026-07-02 02:07:06 +07:00

28 lines
783 B
Python

"""Shared event bus — decouples producers from WebSocket broadcast.
Modules like x402_marketplace emit events here. main.py's WebSocket
broadcast loop reads from this bus. No circular imports.
"""
from __future__ import annotations
import logging
from typing import Callable
logger = logging.getLogger("wp.event_bus")
_subscribers: list[Callable[[str, dict], None]] = []
def subscribe(fn: Callable[[str, dict], None]) -> None:
"""Register a callback for all events."""
_subscribers.append(fn)
def emit(event_type: str, data: dict) -> None:
"""Emit an event to all subscribers (fire-and-forget)."""
for fn in _subscribers:
try:
fn(event_type, data)
except Exception as e:
logger.debug(f"Event subscriber error: {e}")