Completed
Push — master ( c2ba48...1fd225 )
by Markus
14s queued 12s
created

EventQueueWorker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Jellyfish\Event;
4
5
class EventQueueWorker implements EventQueueWorkerInterface
6
{
7
    /**
8
     * @var \Jellyfish\Event\EventQueueConsumerInterface
9
     */
10
    protected $eventQueueConsumer;
11
    /**
12
     * @var \Jellyfish\Event\EventDispatcherInterface
13
     */
14
    protected $eventDispatcher;
15
16
    /**
17
     * @param \Jellyfish\Event\EventDispatcherInterface $eventDispatcher
18
     * @param \Jellyfish\Event\EventQueueConsumerInterface $eventQueueConsumer
19
     */
20
    public function __construct(
21
        EventDispatcherInterface $eventDispatcher,
22
        EventQueueConsumerInterface $eventQueueConsumer
23
    ) {
24
        $this->eventDispatcher = $eventDispatcher;
25
        $this->eventQueueConsumer = $eventQueueConsumer;
26
    }
27
28
    /**
29
     * @return void
30
     */
31
    public function start(): void
32
    {
33
        $listeners = $this->eventDispatcher->getListeners(EventListenerInterface::TYPE_ASYNC);
34
35
        while (true) {
36
            foreach ($listeners as $eventName => $listenersPerEvent) {
37
                foreach ($listenersPerEvent as $listenerIdentifier => $listener) {
38
                    $this->eventQueueConsumer->dequeueEventAsProcess($eventName, $listenerIdentifier);
39
                }
40
            }
41
        }
42
    }
43
}
44