-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unresolved promises on lost connection in client
- Loading branch information
Showing
5 changed files
with
135 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Zikarsky\React\Gearman; | ||
|
||
class ConnectionLostException extends \Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
use React\Stream\Stream; | ||
use React\Promise\Deferred; | ||
use BadMethodCallException; | ||
use Zikarsky\React\Gearman\ConnectionLostException; | ||
|
||
/** | ||
* The connection wraps around the non-async version of the protocol buffers | ||
|
@@ -24,7 +25,6 @@ | |
* @event close When the connection closed "close" is emitted | ||
* | ||
* @author Benjamin Zikarsky <[email protected]> | ||
*/ | ||
class Connection extends EventEmitter | ||
{ | ||
|
@@ -67,14 +67,14 @@ class Connection extends EventEmitter | |
* Creates the connection on top of the async stream and with the given | ||
* command-factory/specification | ||
* | ||
* @param Stream $stream | ||
* @param Stream $stream | ||
* @param CommandFactoryInterface $commandFactory | ||
*/ | ||
public function __construct(Stream $stream, CommandFactoryInterface $commandFactory) | ||
{ | ||
$this->commandFactory = $commandFactory; | ||
$this->writeBuffer = new WriteBuffer(); | ||
$this->readBuffer = new ReadBuffer($commandFactory); | ||
$this->writeBuffer = new WriteBuffer(); | ||
$this->readBuffer = new ReadBuffer($commandFactory); | ||
$this->stream = $stream; | ||
$this->logger = new NullLogger(); | ||
|
||
|
@@ -95,6 +95,11 @@ public function __construct(Stream $stream, CommandFactoryInterface $commandFact | |
} | ||
$this->commandSendQueue = []; | ||
}); | ||
$this->on('close', function () { | ||
foreach ($this->commandSendQueue as $deferred) { | ||
$deferred->reject(new ConnectionLostException()); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
|
@@ -143,7 +148,7 @@ protected function handleData($data) | |
/** | ||
* Sends a command over the stream | ||
* | ||
* @param CommandInterface $command | ||
* @param CommandInterface $command | ||
* @throws BadMethodCallException when the connection is closed | ||
* @return \React\Promise\Promise|\React\Promise\PromiseInterface | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters