Skip to main content
Handler return values are captured in EventResult records and can be consumed as a single value or aggregated across handlers. Repository example files:

Typed return values

Use the event result type to enforce return typing across handlers.
from bubus import BaseEvent, EventBus

class DoMathEvent(BaseEvent[int]):
    a: int
    b: int

def add(event: DoMathEvent) -> int:
    return event.a + event.b

bus = EventBus('AppBus')
bus.on(DoMathEvent, add)

event = await bus.emit(DoMathEvent(a=2, b=3))
result = await event.event_result()

Aggregating multiple handler results

When multiple handlers respond to the same event, collect all results and combine them as needed.
from bubus import BaseEvent, EventBus

class GetConfigEvent(BaseEvent[dict]):
    pass

async def user_config(_: GetConfigEvent) -> dict:
    return {'debug': True, 'port': 8080}

async def system_config(_: GetConfigEvent) -> dict:
    return {'debug': False, 'timeout': 30}

bus = EventBus('AppBus')
bus.on(GetConfigEvent, user_config)
bus.on(GetConfigEvent, system_config)

event = await bus.emit(GetConfigEvent())
merged = await event.event_results_flat_dict(raise_if_conflicts=False)

Per-handler inspection

Both implementations keep per-handler result metadata in addition to flattened helpers.
by_name = await event.event_results_by_handler_name(raise_if_any=False, raise_if_none=False)