Skip to content

Commit

Permalink
Merge pull request #27 from dpovshed/patch-1
Browse files Browse the repository at this point in the history
Small fix to emitter of 'data' event
  • Loading branch information
WyriHaximus committed May 14, 2015
2 parents 4f42ccc + 6781887 commit e0d9994
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ Interesting events emitted by Request:

* `response`: The response headers were received from the server and successfully
parsed. The first argument is a Response instance.
* `error`: An error occured.
* `end`: The request is finished. If an error occured, it is passed as first
* `error`: An error occurred.
* `end`: The request is finished. If an error occurred, it is passed as first
argument. Second and third arguments are the Response and the Request.

Interesting events emitted by Response:

* `data`: Passes a chunk of the response body as first argument
* `error`: An error occured.
* `data`: Passes a chunk of the response body as first argument and a Response
object itself as second argument.
* `error`: An error occurred.
* `end`: The response has been fully received. If an error
occured, it is passed as first argument
occurred, it is passed as first argument.

### Example

Expand All @@ -43,7 +44,7 @@ $client = $factory->create($loop, $dnsResolver);

$request = $client->request('GET', 'https://github.com/');
$request->on('response', function ($response) {
$response->on('data', function ($data) {
$response->on('data', function ($data, $response) {
// ...
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function handleData($data)

$this->emit('response', array($response, $this));

$response->emit('data', array($bodyChunk));
$response->emit('data', array($bodyChunk, $response));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use React\Stream\WritableStreamInterface;

/**
* @event data
* @event data ($bodyChunk, Response $thisResponse)
* @event error
* @event end
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function requestShouldBindToStreamEventsAndUseconnector()

$response->expects($this->once())
->method('emit')
->with('data', array('body'));
->with('data', array('body', $response));

$response->expects($this->at(0))
->method('on')
Expand Down

0 comments on commit e0d9994

Please sign in to comment.