File tree Expand file tree Collapse file tree 3 files changed +42
-5
lines changed Expand file tree Collapse file tree 3 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -56,11 +56,31 @@ $eventDispatcher = $factory->__invoke($container);
56
56
$container->set(EventDispatcherInterface::class, $eventDispatcher);
57
57
````
58
58
59
+ #### Async Event Dispatcher Factory
60
+
61
+
62
+
63
+ ``` bash
64
+ composer require react/event-loop
65
+ ```
66
+
67
+ ```` php
68
+ <?php
69
+
70
+ use Antidot\Event\Container\AsyncEventDispatcherFactory;
71
+ use Psr\EventDispatcher\EventDispatcherInterface;
72
+
73
+ $factory = new AsyncEventDispatcherFactory();
74
+
75
+ $eventDispatcher = $factory->__invoke($container);
76
+ $container->set(EventDispatcherInterface::class, $eventDispatcher);
77
+ ````
78
+
59
79
## Usage
60
80
61
81
### Send events
62
82
63
- ```` php
83
+ ``` php
64
84
<?php
65
85
66
86
use Psr\EventDispatcher\EventDispatcherInterface;
@@ -69,5 +89,20 @@ use Psr\EventDispatcher\EventDispatcherInterface;
69
89
$eventDispatcher = $container->get(EventDispatcherInterface::class);
70
90
71
91
$eventDispatcher->dispatch(SomeEvent::occur());
92
+ ```
72
93
73
- ````
94
+ ### Send events Async mode
95
+
96
+ ``` php
97
+ <?php
98
+
99
+ use Psr\EventDispatcher\EventDispatcherInterface;
100
+ use React\EventLoop\Loop;
101
+
102
+ /** @var \Psr\Container\ContainerInterface $container */
103
+ $eventDispatcher = $container->get(EventDispatcherInterface::class);
104
+
105
+ $eventDispatcher->dispatch(SomeEvent::occur());
106
+
107
+ Loop::run()
108
+ ```
Original file line number Diff line number Diff line change 14
14
],
15
15
"require" : {
16
16
"php" : " ^7.4|^8.0" ,
17
- "psr/event-dispatcher" : " ^1.0" ,
18
- "react/event-loop" : " ^1.2"
17
+ "psr/event-dispatcher" : " ^1.0"
19
18
},
20
19
"require-dev" : {
21
20
"infection/infection" : " ^0.21.0" ,
22
21
"phpro/grumphp" : " ^1.0" ,
23
22
"phpstan/phpstan" : " ^0.12" ,
24
23
"phpunit/phpunit" : " ^8.0 || ^9.0" ,
24
+ "react/event-loop" : " ^1.2" ,
25
25
"squizlabs/php_codesniffer" : " ^3.4" ,
26
26
"symfony/var-dumper" : " ^4.2 || ^5.0" ,
27
27
"vimeo/psalm" : " ^4.4"
54
54
"config" : {
55
55
"sort-packages" : true
56
56
},
57
+ "suggest" : {
58
+ "react/event-loop" : " If you want to run Async Event Dispatcher implementation."
59
+ },
57
60
"extra" : {
58
61
"laminas" : {
59
62
"config-provider" : " Antidot\\ Event\\ Container\\ Config\\ ConfigProvider"
Original file line number Diff line number Diff line change 3
3
namespace Antidot \Test \Event ;
4
4
5
5
use Antidot \Event \AsyncEventDispatcher ;
6
- use Antidot \Event \EventDispatcher ;
7
6
use Antidot \Event \ListenerInterface ;
8
7
use PHPUnit \Framework \TestCase ;
9
8
use Psr \EventDispatcher \ListenerProviderInterface ;
You can’t perform that action at this time.
0 commit comments