Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Rainville committed Nov 13, 2024
1 parent b1b7185 commit a191094
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion examples/basic-usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require __DIR__ . '/../vendor/autoload.php';

use Amp\TimeoutCancellation;
use ArchiPro\EventDispatcher\AsyncEventDispatcher;
use ArchiPro\EventDispatcher\Event\AbstractStoppableEvent;
use ArchiPro\EventDispatcher\ListenerProvider;
Expand Down Expand Up @@ -47,5 +48,15 @@ function () use ($event) {
$event = new UserCreatedEvent('123', '[email protected]');
$dispatcher->dispatch($event);

// Run the event loop
// Run the event loop to process all events
EventLoop::run();

// Wait for the event to finish right away
$event = new UserCreatedEvent('456', '[email protected]');
$future = $dispatcher->dispatch($event);
$updatedEvent = $future->await();

// Make an event cancellable
$event = new UserCreatedEvent('789', '[email protected]');
$future = $dispatcher->dispatch($event, new TimeoutCancellation(30));
EventLoop::run();

0 comments on commit a191094

Please sign in to comment.