← Async

ASYNC FEATURE

Sync Events

Dispatch an event and all sync listeners run before the response is sent.

Feature Guide

A quick orientation block that answers the essential questions: what this feature does, how it works, why it matters, and the key concepts behind it.

What this does

Events decouple side effects from handlers. Dispatch an event and listeners react — notifications, cache invalidation, analytics.

How it works

EventDispatcher::create() builds the event, dispatch() triggers all registered listeners, and propagated events can also be mirrored into Semitexa Ledger for cross-node delivery. #[AsEventListener] marks listener classes. Default execution is synchronous in the same coroutine.

Why it matters

Events let handlers focus on the main task. Side effects belong in listeners, keeping handler code clean and each concern independently testable.

Key concepts

#[AsEventListener]
Registers a class as a listener for a specific event type.
#[Propagated]
Marks an event for ledger persistence and cross-node propagation when the ledger runtime is enabled.
EventDispatcher
Core service for creating and dispatching domain events.

Inline Dispatch

Fire an event in the current request

No event fired yet. Submit the form to dispatch DemoItemCreated.

#[AsEvent] #[Propagated] #[AsEventListener] EventExecution::Sync EventDispatcherInterface

Verified against Semitexa Ultimate 2026.09.19.1020

Sync Events

Synchronous listeners execute inline before the response is sent. When you dispatch an event in sync mode, every registered listener completes its work before the HTTP response is returned to the client.

Event execution modesEvent execution modes. Event dispatcher: Receives one event. Sync listener: Runs before response. Deferred listener: Runs after response. Queued listener: Crosses durable transport. HTTP response: Waits for sync only. Queue worker: Handles durable workinlineafter responseenqueuecomplete firstconsumeEvent dispatcherReceives one eventSync listenerRuns before responseDeferred listenerRuns after responseQueued listenerCrosses durable transportHTTP responseWaits for sync onlyQueue workerHandles durable work
Event execution modes

How it works

The event dispatcher calls each sync listener in registration order within the current request lifecycle. The response is not flushed until all sync listeners have returned.

Why this matters

Sync execution guarantees that listener side effects are complete before the client sees the response. This is the right choice for validation side effects, required audit writes, or any work the response depends on. When the ledger runtime is enabled, propagated events are also written to the node ledger after sync listener execution.

© Edsger W. Dijkstra: "Simplicity is prerequisite for reliability."

Event Implementation slice
<?phpdeclare(strict_types=1);namespace App\Application\Event;use Semitexa\Core\Attribute\AsEvent;#[AsEvent]final class DemoItemCreated{    public function __construct(        public readonly string $itemId,        public readonly string $itemName,        public readonly string $section,    ) {}}

How it works

EventDispatcher::create() builds the event, dispatch() triggers all registered listeners, and propagated events can also be mirrored into Semitexa Ledger for cross-node delivery. #[AsEventListener] marks listener classes. Default execution is synchronous in the same coroutine.

Why it matters

Events let handlers focus on the main task. Side effects belong in listeners, keeping handler code clean and each concern independently testable.

Key concepts

#[AsEventListener]
Registers a class as a listener for a specific event type.
#[Propagated]
Marks an event for ledger persistence and cross-node propagation when the ledger runtime is enabled.
EventDispatcher
Core service for creating and dispatching domain events.

Support Semitexa
Built for developers who prefer control over magic. Your support helps keep it fast, open, and evolving.

Donate via PayPal