Skip to content

Commit 5897351

Browse files
committed
Fix error reporting and closing connection
1 parent 96221a3 commit 5897351

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

example/commands.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
use Clue\React\Ami\Client;
55
use Clue\React\Ami\Api;
66
use Clue\React\Ami\Protocol\Response;
7-
use Clue\React\Ami\Protocol\Event;
8-
use Clue\React\Ami\Protocol\ErrorException;
97

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

@@ -24,19 +22,21 @@
2422
echo 'Commands: ' . implode(', ', array_keys($response->getParts())) . PHP_EOL;
2523
});
2624

27-
$client->on('close', function() {
25+
$client->on('close', function() use ($loop) {
2826
echo 'Closed' . PHP_EOL;
27+
28+
$loop->removeReadStream(STDIN);
2929
});
3030

3131
$loop->addReadStream(STDIN, function () use ($api) {
3232
$line = trim(fread(STDIN, 4096));
3333
echo '<' . $line . PHP_EOL;
3434

3535
$api->command($line)->then(
36-
function(Response $response) {
36+
function (Response $response) {
3737
echo $response->getPart('_') . PHP_EOL;
3838
},
39-
function (ErrorException $error) use ($line) {
39+
function (Exception $error) use ($line) {
4040
echo 'Error executing "' . $line . '": ' . $error->getMessage() . PHP_EOL;
4141
}
4242
);

0 commit comments

Comments
 (0)