1
0
Fork 0

Improve implementation

pull/112/head
Felix Becker 2016-10-25 23:43:15 +02:00
parent 31dc27775f
commit e7fcd48722
1 changed files with 5 additions and 4 deletions

View File

@ -34,13 +34,15 @@ class ProtocolStreamWriter implements ProtocolWriter
* Sends a Message to the client
*
* @param Message $msg
* @return void
* @return Promise Resolved when the message has been fully written out to the output stream
*/
public function write(Message $msg)
{
// if the message queue is currently empty, register a write handler.
if (empty($this->messages)) {
Loop\addWriteStream($this->output, [$this, 'writeData']);
Loop\addWriteStream($this->output, function () {
$this->flush();
});
}
$promise = new Promise();
@ -53,11 +55,10 @@ class ProtocolStreamWriter implements ProtocolWriter
/**
* Writes pending messages to the output stream.
* Must be public to be able to be used as a callback.
*
* @return void
*/
public function writeData()
private function flush()
{
$keepWriting = true;
while ($keepWriting) {