Skip to main content
EventBus is the central runtime for handler registration, event emit, history lookup, and lifecycle control.

EventBus(...)

Shared configuration semantics

Defaults are resolved at processing time on each bus, not copied onto the event at emit. When event fields are unset (None/null/zero-value mode), the current processing bus applies its own defaults, so forwarded events can inherit the target bus defaults.

Runtime state

All implementations expose equivalent runtime state:
  • Bus identity: id, name, label
  • Registered handlers and indexes
  • Event history and pending queue
  • In-flight tracking
  • Locking/concurrency runtime objects

on(...)

Registers a handler for an event key (EventClass, event type string, or '*').

off(...)

Unregisters handlers by event key, handler function/reference, or handler id.

emit(...)

emit(...) enqueues synchronously and returns the pending event immediately.

find(...)

find(...) supports history lookup, optional future waiting, predicate filtering, and parent/child scoping.

filter(...)

filter(...) takes the same arguments as find(...) but returns the list of all matching events (newest to oldest) instead of just the first match. Accepts an additional limit argument to cap the result count.

Lifecycle helpers

Wait for idle

Parent/child relationship checks

Execution pipeline

All runtimes expose the same public processing contract:
  • emit(...) accepts the event, records it in bus history, and queues it for processing.
  • find(...) can observe accepted events before handlers finish.
  • Event-level timeout and slow-warning settings apply to the whole event.
  • Handler-level timeout and slow-warning settings apply to each handler.
  • event_concurrency, event_handler_concurrency, and event_handler_completion choose queueing and completion behavior.
  • Handler return values and errors are stored in event_results; use the result helpers to retrieve typed raw values.

Serialization and teardown

All runtimes can serialize the entire bus state (config, handlers metadata, event history, pending queue), restore it, re-attach handler callables, and continue processing.

destroy(...)

Destroy stops runtime work and optionally clears bus-owned state.
  • clear defaults to true in every runtime.
  • With clear=true, destroy is terminal and clears handlers, history, queues, in-flight tracking, waiters, locks, and dispatch/context state so the bus can be released.
  • With clear=false, destroy is still terminal and the bus cannot be used again; it only preserves handlers/history for inspection.
  • Destroying one bus only clears that bus’s local state; shared event objects, handler functions, and other buses are not destroyed.

Timeout and precedence

Shared precedence model:
  1. Handler override
  2. Event override
  3. Bus default
Effective handler timeout is capped by event timeout when both are set.