-
Notifications
You must be signed in to change notification settings - Fork 2
/
events_handlers_exact.php
35 lines (28 loc) · 1.25 KB
/
events_handlers_exact.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
<?php
/**
* ---------------------------------------------------------------------------------------------------------------------
* DESCRIPTION
* ---------------------------------------------------------------------------------------------------------------------
* This file contains the example of using exact events with EventEmitter.
*
* ---------------------------------------------------------------------------------------------------------------------
* USAGE
* ---------------------------------------------------------------------------------------------------------------------
* To run this example in CLI from project root use following syntax
*
* $> php ./example/events_handlers_exact.php
*
* ---------------------------------------------------------------------------------------------------------------------
*/
require_once __DIR__ . '/bootstrap/autoload.php';
use Dazzle\Event\EventEmitter;
$emitter = new EventEmitter();
// this handler will fire exactly 3 times, then it will be dropped from emitter.
$emitter->times('event.number', 3, function($number) {
echo "Event has been fired with \$number=$number.\n";
});
$counter = 0;
$counterMax = 5;
while ($counter < $counterMax) {
$emitter->emit('event.number', [ ++$counter ]);
}