Skip to content

Commit 2cb425b

Browse files
committed
Add async on readme
1 parent 07803f4 commit 2cb425b

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,31 @@ $eventDispatcher = $factory->__invoke($container);
5656
$container->set(EventDispatcherInterface::class, $eventDispatcher);
5757
````
5858

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+
5979
## Usage
6080

6181
### Send events
6282

63-
````php
83+
```php
6484
<?php
6585

6686
use Psr\EventDispatcher\EventDispatcherInterface;
@@ -69,5 +89,20 @@ use Psr\EventDispatcher\EventDispatcherInterface;
6989
$eventDispatcher = $container->get(EventDispatcherInterface::class);
7090

7191
$eventDispatcher->dispatch(SomeEvent::occur());
92+
```
7293

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+
```

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
],
1515
"require": {
1616
"php": "^7.4|^8.0",
17-
"psr/event-dispatcher": "^1.0",
18-
"react/event-loop": "^1.2"
17+
"psr/event-dispatcher": "^1.0"
1918
},
2019
"require-dev": {
2120
"infection/infection": "^0.21.0",
2221
"phpro/grumphp": "^1.0",
2322
"phpstan/phpstan": "^0.12",
2423
"phpunit/phpunit": "^8.0 || ^9.0",
24+
"react/event-loop": "^1.2",
2525
"squizlabs/php_codesniffer": "^3.4",
2626
"symfony/var-dumper": "^4.2 || ^5.0",
2727
"vimeo/psalm": "^4.4"
@@ -54,6 +54,9 @@
5454
"config": {
5555
"sort-packages": true
5656
},
57+
"suggest": {
58+
"react/event-loop": "If you want to run Async Event Dispatcher implementation."
59+
},
5760
"extra": {
5861
"laminas": {
5962
"config-provider": "Antidot\\Event\\Container\\Config\\ConfigProvider"

test/AsyncEventDispatcherTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Antidot\Test\Event;
44

55
use Antidot\Event\AsyncEventDispatcher;
6-
use Antidot\Event\EventDispatcher;
76
use Antidot\Event\ListenerInterface;
87
use PHPUnit\Framework\TestCase;
98
use Psr\EventDispatcher\ListenerProviderInterface;

0 commit comments

Comments
 (0)