Events
Events
Section titled “Events”Events lets application components notify listeners without depending on each listener’s implementation. Titanspan uses Blinker to retain listener registrations and applies framework ordering, dependency injection, and application lifecycle rules around it.
Events can dispatch plain Python objects, typed classes, or named string events. It works in an application or with a standalone dispatcher. Event objects remain in memory. Titanspan does not serialize them automatically.
Declare an event
Section titled “Declare an event”Use a frozen dataclass when an event should carry a stable value snapshot. Event classes do not need to inherit from a Titanspan base class.
from dataclasses import dataclass
@dataclass(frozen=True, slots=True)class DocumentProcessed: """Identify a completed document operation."""
document_id: str workflow_id: strThe optional Dispatchable mixin adds class-based convenience methods. See
Dispatching.
Register and dispatch
Section titled “Register and dispatch”Use the Event facade when an application context is active:
from titanspan.facades import Event
Event.listen(DocumentProcessed, notify_owner)responses = Event.dispatch(DocumentProcessed("doc-1", "run-1"))The facade resolves the same dispatcher as constructor injection and the
event() helpers. See Listeners and discovery
for listener forms and registration options.
Use the asynchronous path
Section titled “Use the asynchronous path”Synchronous dispatch accepts sync-safe listeners. Use dispatch_async() when
any matching listener is asynchronous:
responses = await Event.dispatch_async( DocumentProcessed("doc-1", "run-1"),)Async dispatch runs listeners sequentially and awaits each listener before starting the next. It does not create background tasks or parallel work.
Available integrations
Section titled “Available integrations”The dispatcher, listener injection, scoped fakes, deferred dispatch, trusted module discovery, JSON manifests, and event inspection commands are implemented. Queue execution, database transaction callbacks, and broadcasting await their owning Titanspan components.
Read dispatch semantics, listeners and discovery, testing and lifecycle, and the behavioral specification.
