Skip to content

Commit 554b31d

Browse files
authored
Merge pull request #56 from WyriHaximus-labs/4.x-clean-up-loop-left-overs-from-promise
Clean up event loop left overs from promise
2 parents a7a4500 + 931ef9a commit 554b31d

File tree

3 files changed

+7
-28
lines changed

3 files changed

+7
-28
lines changed

src/Client.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public function sendAsyncRequest(RequestInterface $request)
6969
$request->getHeaders(),
7070
$request->getBody()
7171
),
72-
$this->loop,
7372
$request
7473
);
7574

src/Promise.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
use function React\Async\await;
1212

13-
use React\EventLoop\LoopInterface;
1413
use React\Promise\PromiseInterface;
15-
use RuntimeException;
1614

1715
/**
1816
* React promise adapter implementation.
@@ -58,19 +56,11 @@ final class Promise implements HttpPromise
5856
*/
5957
private $promise;
6058

61-
/**
62-
* ReactPHP LoopInterface.
63-
*
64-
* @var LoopInterface
65-
*/
66-
private $loop;
67-
68-
public function __construct(PromiseInterface $promise, LoopInterface $loop, RequestInterface $request)
59+
public function __construct(PromiseInterface $promise, RequestInterface $request)
6960
{
7061
$this->state = self::PENDING;
7162

7263
$this->request = $request;
73-
$this->loop = $loop;
7464
$this->promise = $promise->then(
7565
function (?ResponseInterface $response): ?ResponseInterface {
7666
$this->response = $response;
@@ -86,7 +76,7 @@ function ($reason): void {
8676

8777
if ($reason instanceof HttplugException) {
8878
$this->exception = $reason;
89-
} elseif ($reason instanceof RuntimeException) {
79+
} elseif ($reason instanceof \RuntimeException) {
9080
$this->exception = new HttplugException\NetworkException($reason->getMessage(), $this->request, $reason);
9181
} elseif ($reason instanceof \Throwable) {
9282
$this->exception = new HttplugException\TransferException('Invalid exception returned from ReactPHP', 0, $reason);
@@ -101,7 +91,7 @@ function ($reason): void {
10191

10292
public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
10393
{
104-
return new self($this->promise->then($onFulfilled, $onRejected), $this->loop, $this->request);
94+
return new self($this->promise->then($onFulfilled, $onRejected), $this->request);
10595
}
10696

10797
/**

tests/PromiseTest.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,17 @@
44

55
use Http\Adapter\React\Exception\UnexpectedValueException;
66
use Http\Adapter\React\Promise;
7-
use Http\Adapter\React\ReactFactory;
87
use Http\Client\Exception\HttpException;
98
use Http\Client\Exception\NetworkException;
109
use Http\Client\Exception\TransferException;
11-
use InvalidArgumentException;
1210
use Nyholm\Psr7\Factory\Psr17Factory;
1311
use PHPUnit\Framework\TestCase;
1412
use Psr\Http\Message\RequestInterface;
1513
use Psr\Http\Message\ResponseInterface;
1614
use React\Promise\Promise as ReactPromise;
17-
use RuntimeException;
1815

1916
class PromiseTest extends TestCase
2017
{
21-
private $loop;
22-
23-
public function setUp(): void
24-
{
25-
$this->loop = ReactFactory::buildEventLoop();
26-
}
27-
2818
public function testChain()
2919
{
3020
$factory = new Psr17Factory();
@@ -35,7 +25,7 @@ public function testChain()
3525
$resolve($response);
3626
});
3727

38-
$promise = new Promise($reactPromise, $this->loop, $request);
28+
$promise = new Promise($reactPromise, $request);
3929

4030
$lastPromise = $promise->then(function (ResponseInterface $response) use ($factory) {
4131
return $factory->createResponse(300, $response->getReasonPhrase());
@@ -60,7 +50,7 @@ public function testPromiseExceptionsAreTranslatedToHttplug(
6050
$reject($reason);
6151
});
6252

63-
$promise = new Promise($reactPromise, $this->loop, $request);
53+
$promise = new Promise($reactPromise, $request);
6454
$this->expectException($adapterExceptionClass);
6555
$promise->wait();
6656
}
@@ -72,8 +62,8 @@ public function exceptionThatIsThrownFromReactProvider()
7262

7363
return [
7464
'string' => [$request, 'whatever', UnexpectedValueException::class],
75-
'InvalidArgumentException' => [$request, new InvalidArgumentException('Something went wrong'), TransferException::class],
76-
'RuntimeException' => [$request, new RuntimeException('Something happened inside ReactPHP engine'), NetworkException::class],
65+
'InvalidArgumentException' => [$request, new \InvalidArgumentException('Something went wrong'), TransferException::class],
66+
'RuntimeException' => [$request, new \RuntimeException('Something happened inside ReactPHP engine'), NetworkException::class],
7767
'NetworkException' => [$request, new NetworkException('Something happened inside ReactPHP engine', $request), NetworkException::class],
7868
'HttpException' => [$request, new HttpException('Something happened inside ReactPHP engine', $request, $response), HttpException::class],
7969
];

0 commit comments

Comments
 (0)