Help - integrate amphp/mysql into ratchet
I use `ratchet` and i want use anync mysql client.
Can you set an example?

My bogus example. Can you point to mistakes?
server.php:
```php
<?php
use Ratchet\Wamp\WampServer;
use Ratchet\Server\IoServer;
use React\EventLoop\Factory;
use Ratchet\WebSocket\WsServer;
use React\Socket\Server;
use Ratchet\Http\HttpServer;

require __DIR__ . '/../vendor/autoload.php';

\Config\IniConfig::init(__DIR__ . '/../application.ini');


// https://github.com/reactphp/event-loop/issues/152#issuecomment-368031909
$loop = new Amp\ReactAdapter\ReactAdapter((new Amp\Loop\DriverFactory())->create());
//$loop = Factory::create();

$webSock = new Server('127.0.0.1:' . \Config\IniConfig::getInstance()->getKey('ws_port', 'parameters'), $loop);

new IoServer(
    new HttpServer(
        new WsServer(
            new WampServer(
                new WebSocket\Example($loop, \Config\IniConfig::getInstance())
            )
        )
    ),
    $webSock,
    $loop
);

echo '[' . \date(\DATE_ATOM) . ']: Websocket server started.' . "\n";
\register_shutdown_function(function() {
    echo '[' . \date(\DATE_ATOM) . ']: Websocket server shutdown.' . "\n";
});

$loop->run();
```

Example.php
```php
<?php
namespace WebSocket;

use Config\IniConfig;
use Ratchet\Wamp\WampServerInterface;
use Ratchet\ConnectionInterface;
use React\EventLoop\LoopInterface;
use Ratchet\MessageComponentInterface;


class Example implements WampServerInterface, MessageComponentInterface
{
    const LOOP_TIMER = 10;

    /**
     * @var LoopInterface
     */
    private $loop;
    /**
     * @var \Amp\Mysql\Statement
     */
    private $userQ;
    /**
     * @var IniConfig
     */
    private $iniConfig;
    /**
     * @var Client[] List of connected clients
     */
    private $clients = array();

    /**
     * Example constructor.
     * @param LoopInterface $loop
     * @param IniConfig $iniConfig
     * @throws \Amp\Mysql\ConnectionException
     * @throws \Amp\Mysql\FailureException
     */
    public function __construct(LoopInterface $loop, IniConfig $iniConfig)
    {
        var_dump(__METHOD__ . ' started');
        $this->loop = $loop;
        $this->iniConfig = $iniConfig;

        $pool = \Amp\Mysql\pool(
            'host='.$this->iniConfig->getKey('database_topby_host', 'database').
            ' user='.$this->iniConfig->getKey('database_topby_user', 'database').
            ' password='.$this->iniConfig->getKey('database_topby_password', 'database').
            ' db='.$this->iniConfig->getKey('database_topby_name', 'database')
        );

        $this->userQ = yield $pool->prepare('SELECT * FROM esb2b_members WHERE es_id = :es_id');

        var_dump(__METHOD__ . ' ended');
    }


    /**
     * @param ConnectionInterface $conn
     * @return array|\Generator
     * @throws \Throwable
     */
    private function makeUserData(ConnectionInterface $conn)
    {
        var_dump(__METHOD__ . ' started');

        /** @var \Psr\Http\Message\RequestInterface $request */
        $request = $conn->httpRequest;

        $query = array();
        \parse_str($request->getUri()->getQuery(), $query);
        if (!isset($query['id'])) {
            throw new \InvalidArgumentException('User not found');
        }

        /** @var \Amp\Mysql\ResultSet $result */
        $result = yield $this->userQ->execute(array(':es_id' => $query['id']));
        yield $result->advance();

        var_dump(__METHOD__ . ' ended');

        return $result->getCurrent();
    }


    /**
     * A user connects, we store the connection by the unique resource id
     * @param \Ratchet\Wamp\WampConnection|ConnectionInterface $conn
     * @throws \Throwable
     */
    public function onOpen(ConnectionInterface $conn)
    {
        var_dump(__METHOD__ . ' started');
        $this->clients[$conn->resourceId] = yield $this->makeUserData($conn);
        var_dump(__METHOD__ . ' ended');
    }

    /**
     * A user subscribes. The JSON is in $subscription->getId()
     * @param \Ratchet\Wamp\WampConnection|ConnectionInterface $conn
     * @param string|\Ratchet\Wamp\Topic $subscription
     */
    public function onSubscribe(ConnectionInterface $conn, $subscription)
    {
        var_dump(__METHOD__ . ' started');
        if (!isset($this->clients[$conn->resourceId])) {
            var_dump(__METHOD__ . ' ended without client');
            return;
        }

        var_dump(__METHOD__ . ' docs before getUserData');
        $userData = $this->clients[$conn->resourceId];
        var_dump(__METHOD__ . ' docs after getUserData');

        $caller = function () use ($subscription, $userData, $conn) {
            // custom logic
            return $conn->event($subscription, \json_encode($userData));
        };
        $caller(); // first run

        $timer = $this->loop->addPeriodicTimer(self::LOOP_TIMER, $caller);

        $this->clients[$conn->resourceId]['timer'] = $timer;

        var_dump(__METHOD__ . ' ended with client');
    }

    /**
     * @param \Ratchet\Wamp\WampConnection|ConnectionInterface $conn
     */
    public function onClose(ConnectionInterface $conn)
    {
        var_dump(__METHOD__ . ' started');
        if (!isset($this->clients[$conn->resourceId])) {
            var_dump(__METHOD__ . ' ended without client');
            return;
        }

        $timer = $this->clients[$conn->resourceId]['timer'];
        if ($timer) {
            $this->loop->cancelTimer($timer);
        }
        unset($this->clients[$conn->resourceId]);
        var_dump(__METHOD__ . ' ended with client');
    }

    /**
     * @param \Ratchet\Wamp\WampConnection|ConnectionInterface $conn
     * @param \Ratchet\Wamp\Topic|string $subscription
     */
    public function onUnSubscribe(ConnectionInterface $conn, $subscription)
    {
        var_dump(__METHOD__ . ' started');
        $subscription->remove($conn);
        $conn->close();
        var_dump(__METHOD__ . ' ended');
    }

    /**
     * @param \Ratchet\Wamp\WampConnection|ConnectionInterface $conn
     * @param string $id
     * @param \Ratchet\Wamp\Topic|string $subscription
     * @param array $params
     */
    public function onCall(ConnectionInterface $conn, $id, $subscription, array $params)
    {
        var_dump(__METHOD__ . ' started');
        // In this application if clients send data it's because the user hacked around in console
        $conn->callError($id, $subscription, 'You are not allowed to make calls')->close();
        var_dump(__METHOD__ . ' ended');
    }

    /**
     * @param ConnectionInterface $conn
     * @param \Ratchet\Wamp\Topic|string $topic
     * @param string $event
     * @param array $exclude
     * @param array $eligible
     */
    public function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible)
    {
        var_dump(__METHOD__ . ' started');
        // In this application if clients send data it's because the user hacked around in console
        $conn->close();
        var_dump(__METHOD__ . ' ended');
    }

    /**
     * @param ConnectionInterface $conn
     * @param \Exception $e
     */
    public function onError(ConnectionInterface $conn, \Exception $e)
    {
        var_dump(__METHOD__ . ' started');
        $conn->close();

        \error_log(\print_r(array(
            'message' => $e->getMessage(),
            'trace' => $e->getTraceAsString()
        ), true));
        echo '[' . \date(\DATE_ATOM) . ']: ' . $e->getMessage() . "\n";

        var_dump(__METHOD__ . ' ended');
    }

    /**
     * @param ConnectionInterface $from
     * @param string $msg
     */
    public function onMessage(ConnectionInterface $from, $msg)
    {
        var_dump(__METHOD__ . ' started');
        var_dump(__METHOD__ . ' ended');
    }
}
```


into log i see
```
[2018-03-06T12:38:50+03:00]: Websocket server started.
string(38) "WebSocket\Example::onSubscribe started"
string(51) "WebSocket\Example::onSubscribe ended without client"
```
whats wrong?
@trowski, @kelunik, @cboden