Skip to content

Commit

Permalink
Allow initial connection failure handling
Browse files Browse the repository at this point in the history
  • Loading branch information
calcinai committed May 31, 2019
1 parent 70057c2 commit 8f2a32a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,19 @@ public function connect()
throw new \InvalidArgumentException(sprintf('Invalid scheme [%s]', $uri->scheme));
}

$that = $this;

$this->setState(self::STATE_CONNECTING);

return $connector->connect($scheme . '://' . $uri->host . ':' . $port)->then(function (ConnectionInterface $stream) use ($that) {
$that->transport = new $that->protocol($that, $stream);
$that->transport->upgrade();
});
return $connector->connect($scheme . '://' . $uri->host . ':' . $port)
->then(function (ConnectionInterface $stream) {
$this->transport = new $this->protocol($this, $stream);
$this->transport->upgrade();
})->otherwise(function (\Exception $e) {
$this->emit('error');

if ($this->use_exceptions) {
throw $e;
}
});

}

Expand Down

0 comments on commit 8f2a32a

Please sign in to comment.