Skip to main content
parallel allows multiple handlers for the same event to run at the same time. Companion runnable example:

Lifecycle impact

  1. Event starts processing.
  2. All applicable handlers are scheduled concurrently.
  3. Event completion waits based on completion mode (all or first).
  4. Per-handler timeout/error behavior remains independent per handler.

Execution order example

import asyncio
from bubus import BaseEvent, EventBus

class HandlerEvent(BaseEvent):
    pass

bus = EventBus('ParallelHandlerBus', event_handler_concurrency='parallel')

in_flight = 0
max_in_flight = 0
release = asyncio.Event()

async def tracked(_: HandlerEvent) -> None:
    global in_flight, max_in_flight
    in_flight += 1
    max_in_flight = max(max_in_flight, in_flight)
    await release.wait()
    in_flight -= 1

bus.on(HandlerEvent, tracked)
bus.on(HandlerEvent, tracked)

event = bus.emit(HandlerEvent())
await asyncio.sleep(0)
release.set()
await event

assert max_in_flight >= 2

Notes

  • Best for independent I/O-bound handlers where overlap reduces total latency.
  • If handlers mutate shared resources, add explicit synchronization.