-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAbstractAsyncEventDispatcher.php
46 lines (38 loc) · 1.3 KB
/
AbstractAsyncEventDispatcher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Enqueue\AsyncEventDispatcher;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\EventDispatcher\Event as ContractEvent;
abstract class AbstractAsyncEventDispatcher extends EventDispatcher implements EventDispatcherInterface
{
/**
* @var EventDispatcherInterface
*/
protected $trueEventDispatcher;
/**
* @var AsyncListener
*/
protected $asyncListener;
public function __construct(EventDispatcherInterface $trueEventDispatcher, AsyncListener $asyncListener)
{
$this->trueEventDispatcher = $trueEventDispatcher;
$this->asyncListener = $asyncListener;
}
/**
* This method dispatches only those listeners that were marked as async.
*
* @param string $eventName
* @param ContractEvent|Event|null $event
*/
public function dispatchAsyncListenersOnly($eventName, $event = null)
{
try {
$this->asyncListener->syncMode($eventName);
$this->parentDispatch($event, $eventName);
} finally {
$this->asyncListener->resetSyncMode();
}
}
abstract protected function parentDispatch($event, $eventName);
}