Skip to main content
serial executes handlers for a single event sequentially. Companion runnable example:

Lifecycle impact

  1. Event starts processing.
  2. Handler A runs to completion (or failure/timeout).
  3. Handler B starts afterward, then C, and so on.
  4. Event completion waits for the serial chain (or completion-mode short-circuit rules).

Execution order example

import asyncio
from bubus import BaseEvent, EventBus

class HandlerEvent(BaseEvent):
    pass

bus = EventBus('SerialHandlerBus', event_handler_concurrency='serial')
log: list[str] = []

async def h1(_: HandlerEvent) -> None:
    log.append('h1_start')
    await asyncio.sleep(0.01)
    log.append('h1_end')

async def h2(_: HandlerEvent) -> None:
    log.append('h2_start')
    await asyncio.sleep(0.01)
    log.append('h2_end')

bus.on(HandlerEvent, h1)
bus.on(HandlerEvent, h2)

await bus.emit(HandlerEvent())

assert log == ['h1_start', 'h1_end', 'h2_start', 'h2_end']

Notes

  • Best when handlers share mutable state or require strict ordering.
  • Execution remains predictable but may increase per-event latency.