Skip to content

Use Throwable instead of Exception #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/ReactMqttClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use BinSoul\Net\Mqtt\StreamParser;
use BinSoul\Net\Mqtt\Subscription;
use Evenement\EventEmitter;
use Exception;
use LogicException;
use React\EventLoop\LoopInterface;
use React\EventLoop\TimerInterface;
Expand All @@ -30,6 +29,7 @@
use React\Socket\ConnectorInterface;
use React\Stream\DuplexStreamInterface;
use RuntimeException;
use Throwable;

/**
* Connects to a MQTT broker and subscribes to topics or publishes messages.
Expand Down Expand Up @@ -114,7 +114,7 @@ public function __construct(
$this->parser = new StreamParser(new DefaultPacketFactory());
}

$this->parser->onError(function (Exception $e) {
$this->parser->onError(function (Throwable $e) {
$this->emitWarning($e);
});

Expand Down Expand Up @@ -216,7 +216,7 @@ public function connect(string $host, int $port = 1883, Connection $connection =
$this->emit('connect', [$connection, $this]);
$deferred->resolve($result ?: $connection);
})
->otherwise(function (Exception $e) use ($connection, $deferred) {
->otherwise(function (Throwable $e) use ($connection, $deferred) {
$this->isConnecting = false;

$this->emitError($e);
Expand All @@ -229,7 +229,7 @@ public function connect(string $host, int $port = 1883, Connection $connection =
$this->emit('close', [$connection, $this]);
});
})
->otherwise(function (Exception $e) use ($deferred) {
->otherwise(function (Throwable $e) use ($deferred) {
$this->isConnecting = false;

$this->emitError($e);
Expand Down Expand Up @@ -378,7 +378,7 @@ function () use ($message, $generator, $deferred) {
static function ($value) use ($deferred) {
$deferred->notify($value);
},
static function (Exception $e) use ($deferred) {
static function (Throwable $e) use ($deferred) {
$deferred->reject($e);
}
);
Expand All @@ -391,23 +391,23 @@ static function (Exception $e) use ($deferred) {
/**
* Emits warnings.
*
* @param Exception $e
* @param Throwable $e
*
* @return void
*/
private function emitWarning(Exception $e): void
private function emitWarning(Throwable $e): void
{
$this->emit('warning', [$e, $this]);
}

/**
* Emits errors.
*
* @param Exception $e
* @param Throwable $e
*
* @return void
*/
private function emitError(Exception $e): void
private function emitError(Throwable $e): void
{
$this->emit('error', [$e, $this]);
}
Expand Down Expand Up @@ -451,13 +451,13 @@ static function () use ($deferred, $timeout, &$future) {
$this->handleClose();
});

$stream->on('error', function (Exception $e) {
$stream->on('error', function (Throwable $e) {
$this->handleError($e);
});

$deferred->resolve($stream);
})
->otherwise(static function (Exception $e) use ($deferred) {
->otherwise(static function (Throwable $e) use ($deferred) {
$deferred->reject($e);
});

Expand Down Expand Up @@ -496,7 +496,7 @@ function () {
);

$deferred->resolve($result ?: $connection);
})->otherwise(static function (Exception $e) use ($deferred) {
})->otherwise(static function (Throwable $e) use ($deferred) {
$deferred->reject($e);
});

Expand Down Expand Up @@ -649,11 +649,11 @@ private function handleClose(): void
/**
* Handles errors of the stream.
*
* @param Exception $e
* @param Throwable $e
*
* @return void
*/
private function handleError(Exception $e): void
private function handleError(Throwable $e): void
{
$this->emitError($e);
}
Expand All @@ -670,7 +670,7 @@ private function startFlow(Flow $flow, bool $isSilent = false): ExtendedPromiseI
{
try {
$packet = $flow->start();
} catch (Exception $e) {
} catch (Throwable $e) {
$this->emitError($e);

return new RejectedPromise($e);
Expand Down Expand Up @@ -708,7 +708,7 @@ private function continueFlow(ReactFlow $flow, Packet $packet): void
{
try {
$response = $flow->next($packet);
} catch (Exception $e) {
} catch (Throwable $e) {
$this->emitError($e);

return;
Expand Down