Skip to content

Commit

Permalink
Emit an explicit messages event for multi-part receive
Browse files Browse the repository at this point in the history
The current behaviour is inconsistent because the message event can be
either a single message or in case of a multi-part message, an array.

This patch makes an explicit distinction. The message event is used for
single part messages, the messages even for multi-part. The messages
event is also emitted for single part messages, where the argument is an
array of one single element.

Closes #3.
  • Loading branch information
igorw committed Nov 18, 2012
1 parent ab86fd1 commit 0ac61ce
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,10 @@
CHANGELOG
=========

* 0.1.1 (2012-11-18)

* Feature: Emit `messages` instead of `message` for multi-part receive

* 0.1.0 (2012-10-23)

* Bug fix: Resolve flaw in reading of edge-triggered events
2 changes: 1 addition & 1 deletion examples/http-server/server.php
Expand Up @@ -12,7 +12,7 @@

$conns = new ArrayObject();

$dealer->on('message', function ($msg) use ($conns) {
$dealer->on('messages', function ($msg) use ($conns) {
list($hash, $blank, $data) = $msg;

if (!isset($conns[$hash])) {
Expand Down
5 changes: 2 additions & 3 deletions src/React/ZMQ/SocketWrapper.php
Expand Up @@ -53,11 +53,10 @@ public function handleReadEvent()
{
$messages = $this->socket->recvmulti(\ZMQ::MODE_NOBLOCK);
if (false !== $messages) {
if (count($messages) > 1) {
$this->emit('message', array($messages));
} else {
if (1 === count($messages)) {
$this->emit('message', array($messages[0]));
}
$this->emit('messages', array($messages));
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/React/Tests/ZMQ/IntegrationTest.php
Expand Up @@ -54,7 +54,7 @@ public function testDealerRep()

$msgs = array();

$dealer->on('message', function ($msg) use (&$msgs) {
$dealer->on('messages', function ($msg) use (&$msgs) {
$msgs[] = $msg;
});

Expand Down

0 comments on commit 0ac61ce

Please sign in to comment.