Skip to content

Commit

Permalink
The 'data' event emitted by Response always passing itself as a secon…
Browse files Browse the repository at this point in the history
…d argument.
  • Loading branch information
dpovshed committed May 9, 2015
1 parent d02fb30 commit 6781887
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 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/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 6781887

Please sign in to comment.