Skip to content

Commit 4c65753

Browse files
committed
Clean up event loop from client
1 parent 99bd0fa commit 4c65753

File tree

3 files changed

+4
-36
lines changed

3 files changed

+4
-36
lines changed

src/Client.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,13 @@ class Client implements HttpClient, HttpAsyncClient
2323
*/
2424
private $client;
2525

26-
/**
27-
* React event loop.
28-
*
29-
* @var LoopInterface
30-
*/
31-
private $loop;
32-
3326
/**
3427
* Initialize the React client.
3528
*/
3629
public function __construct(
37-
LoopInterface $loop = null,
3830
ReactBrowser $client = null
3931
) {
40-
if (null !== $client && null === $loop) {
41-
throw new \RuntimeException('You must give a LoopInterface instance with the Client');
42-
}
43-
44-
$this->loop = $loop ?: ReactFactory::buildEventLoop();
45-
$this->client = $client ?: ReactFactory::buildHttpClient($this->loop);
32+
$this->client = $client ?: ReactFactory::buildHttpClient();
4633
}
4734

4835
/**

src/ReactFactory.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,16 @@
1414
*/
1515
class ReactFactory
1616
{
17-
/**
18-
* Build a react Event Loop.
19-
*/
20-
public static function buildEventLoop(): LoopInterface
21-
{
22-
return Loop::get();
23-
}
24-
2517
/**
2618
* Build a React Http Client.
2719
*
2820
* @param ConnectorInterface|null $connector only pass this argument if you need to customize DNS
2921
* behaviour
3022
*/
3123
public static function buildHttpClient(
32-
LoopInterface $loop,
3324
ConnectorInterface $connector = null
3425
): Browser {
35-
return (new Browser($loop, $connector))
26+
return (new Browser($connector))
3627
->withRejectErrorResponse(false)
3728
->withFollowRedirects(false);
3829
}

tests/ReactFactoryTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,17 @@
1616
*/
1717
class ReactFactoryTest extends TestCase
1818
{
19-
/**
20-
* @var \React\EventLoop\LoopInterface
21-
*/
22-
private $loop;
23-
24-
protected function setUp(): void
25-
{
26-
$this->loop = $this->getMockBuilder(LoopInterface::class)->getMock();
27-
}
28-
2919
public function testBuildHttpClientWithConnector()
3020
{
3121
/** @var ConnectorInterface $connector */
3222
$connector = $this->getMockBuilder(ConnectorInterface::class)->getMock();
33-
$client = ReactFactory::buildHttpClient($this->loop, $connector);
23+
$client = ReactFactory::buildHttpClient($connector);
3424
$this->assertInstanceOf(Browser::class, $client);
3525
}
3626

3727
public function testBuildHttpClientWithoutConnector()
3828
{
39-
$client = ReactFactory::buildHttpClient($this->loop);
29+
$client = ReactFactory::buildHttpClient();
4030
$this->assertInstanceOf(Browser::class, $client);
4131
}
4232
}

0 commit comments

Comments
 (0)