Esempio n. 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Lykov bot started</info>');
     $loop = \React\EventLoop\Factory::create();
     $emitter = new \Evenement\EventEmitter();
     $pcntl = new \MKraemer\ReactPCNTL\PCNTL($loop);
     $pcntl->on(SIGTERM, function () use($emitter) {
         $emitter->emit('terminate');
     });
     $pcntl->on(SIGTERM, function () use($emitter) {
         $emitter->emit('terminate');
     });
     $emitter->on('error.fatal', function ($msg) use($loop, $output) {
         $loop->stop();
         $output->writeln('<fg="red">Fatal error occured: ' . $msg . '</fg>');
     });
     $emitter->on('terminate', function () use($loop, $emitter) {
         $emitter->emit('log', ['Terminating...', OutputInterface::VERBOSITY_NORMAL]);
         $loop->stop();
         die;
     });
     $emitter->on('log', function ($msg, $verbosity = OutputInterface::VERBOSITY_DEBUG) use($output) {
         if ($verbosity === OutputInterface::VERBOSITY_DEBUG) {
             $msg = 'DEBUG: ' . $msg;
         }
         if ($output->getVerbosity() >= $verbosity) {
             $output->writeln($msg);
         }
     });
     $apiClient = new SocketClient($loop, $emitter, self::TOKEN_LYKOV_TEST);
     $emitter->emit('send', ['id' => 2, 'type' => 'message', 'channel' => 'D04F44TFL', 'text' => 'hello']);
     $loop->run();
 }
<?php

/**
 * Benchmarking against EventEmitter (original by Igor Wiedler)
 */
$loader = (require __DIR__ . '/../vendor/autoload.php');
require 'diff.php';
$start = millitime();
$emitter = new \Evenement\EventEmitter();
$counter = 1;
$listeners = 100;
$emitters = 10000;
for ($i = 1; $i <= $listeners; $i++) {
    $emitter->on('listener_' . $i, function () use(&$counter) {
        $counter++;
    });
}
for ($i = 1; $i <= $emitters; $i++) {
    $emitter->emit('listener_' . $i);
}
$time_EventEmitter = millitimeDiff($start);
$start = millitime();
$emitter = new \Evenement\EventEmitterRegex();
$counter = 1;
for ($i = 1; $i <= $listeners; $i++) {
    $emitter->on('listener_' . $i, function () use(&$counter) {
        $counter++;
    });
}
for ($i = 1; $i <= $emitters; $i++) {
    $emitter->emit('listener_' . $i . '$');
Esempio n. 3
0
});
$event->on('key3', $env_foo);
$event->on('key4', [new env(), 'foo']);
$event->on('key4', function () {
    return 0;
});
var_dump($event);
echo "removeListener\n\n";
$event->removeListener("key3", $env_foo);
var_dump($event->listeners['key3']);
$ret = array_search($env_foo, $event->listeners['key3'], true);
var_dump($ret);
echo "\n\n";
var_dump($event);
echo "\nlisteners\n";
$value = $event->listeners('key4');
var_dump($value);
$value = $event->listeners('key_none');
var_dump($value);
echo "\nemit\n";
$event->emit('key1', ["Hello World"]);
$event->emit('key1', [new env()]);
echo "\nremoveAllListeners\n";
$event->removeAllListeners();
var_dump($event);
$emitter = new Evenement\EventEmitter();
$emitter->on('user.created', function ($user) {
    var_dump($user);
});
var_dump($emitter);
$emitter->emit('user.created', array("eagle"));