Skip to main content

Event Bus

PrismEventBus is an actor-based pub/sub system that lets different parts of your application communicate without direct dependencies. Define typed events, subscribe to them, and emit them from anywhere.

Defining Events

Custom Events
Events conform to PrismEvent which requires Sendable. The event name defaults to the type name — you can override static var name: String if needed.

Subscribing

Listen for Events

One-Time Listeners

Listen Once

Emitting Events

Publish Events

Practical Example: Audit Logging

Audit Log System

Managing Listeners

Unsubscribe

Built-In Server Events

Prism emits several events automatically:
Server Lifecycle Events
The event bus is great for cross-cutting concerns like logging, analytics, notifications, and cache invalidation. It keeps your route handlers focused on the primary business logic.