Skip to content

Commit a191094

Browse files
author
Maxime Rainville
committed
Update example
1 parent b1b7185 commit a191094

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

examples/basic-usage.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

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

50-
// Run the event loop
51+
// Run the event loop to process all events
52+
EventLoop::run();
53+
54+
// Wait for the event to finish right away
55+
$event = new UserCreatedEvent('456', '[email protected]');
56+
$future = $dispatcher->dispatch($event);
57+
$updatedEvent = $future->await();
58+
59+
// Make an event cancellable
60+
$event = new UserCreatedEvent('789', '[email protected]');
61+
$future = $dispatcher->dispatch($event, new TimeoutCancellation(30));
5162
EventLoop::run();

0 commit comments

Comments
 (0)