The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages

Versions:

Getting Started

Usage

Extra Utilities

Buffered Event Dispatcher

The buffered event dispatcher allows you to stage your events before committing to publishing them. The buffered event dispatcher decorates a Psr\EventDispatching\EventDisparcherInterface instance.

use League\Event\BufferedEventDispatcher;
use League\Event\EventDispatcher;

$internalDispatcher = new EventDispatcher();
$internalDispatcher->subscribeTo(stdClass::class, fn () => echo "Hello!");

$dispatcher = new BufferedEventDispatcher($internalDispatcher);

$dispatcher->dispatch(new stdClass()); // no listener is called;
$dispatcher->dispatch(new stdClass()); // no listener is called;

$dispatcher->dispatchBufferedEvents(); // listener is called twice