/** * @inheritdoc * * @param Task $task */ public function handle(Task $task) { $config = $task->getData(); if ($config["driver"] === "mysql") { $config += ["host" => "127.0.0.1", "port" => 3306, "charset" => "utf8", "socket" => null]; } if ($config["remit"]["driver"] === "zeromq") { $config["remit"]["server"] += ["host" => "127.0.0.1"]; $config["remit"]["client"] += ["host" => "127.0.0.1"]; $server = new ZeroMqServer(new InMemoryLocation($config["remit"]["client"]["host"], $config["remit"]["client"]["port"])); $client = new ZeroMqClient(new InMemoryLocation($config["remit"]["server"]["host"], $config["remit"]["server"]["port"])); } $connection = new ExtendedPdo(new PDO($this->newConnectionString($config), $config["username"], $config["password"])); $server->addListener("q", function ($query, $values, $id) use($client, $connection) { $client->emit("r", [$connection->fetchAll($query, $values), $id]); }); $server->addListener("d", function () use($connection, $server, $client) { $client->emit("dd"); try { $connection->disconnect(); } catch (Exception $exception) { // TODO: find an elegant way to deal with this } $server->disconnect(); $client->disconnect(); Loop\stop(); }); Loop\periodic(0, function () use($server) { $server->tick(); }); Loop\run(); }
/** * @param float $delay * @param mixed $expected * @param mixed $actual */ private function assertEqualsAfterDelay($delay, $expected, $actual) { Loop\timer($delay, function () use($expected, $actual) { $this->assertEquals($expected, $actual); Loop\stop(); }); }
/** * @param mixed $expected * @param mixed $actual */ private function assertEqualsAfterDelay($expected, $actual) { // after a small delay, check for a value Loop\timer(1, function () use($expected, $actual) { $this->assertEquals($expected, $actual); // remember to stop the loop when the test if done Loop\stop(); }); }