Skip to content

Commit 61c7bf6

Browse files
committed
Use reactphp/async instead of clue/reactphp-block
1 parent 41c06ae commit 61c7bf6

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,14 @@ object to contain a list of entries.
375375

376376
As stated above, this library provides you a powerful, async API by default.
377377

378-
If, however, you want to integrate this into your traditional, blocking environment,
379-
you should look into also using [clue/reactphp-block](https://github.com/clue/reactphp-block).
380-
381-
The resulting blocking code could look something like this:
378+
You can also integrate this into your traditional, blocking environment by using
379+
[reactphp/async](https://github.com/reactphp/async). This allows you to simply
380+
await responses on the client like this:
382381

383382
```php
384-
use Clue\React\Block;
385-
use React\EventLoop\Loop;
383+
use function React\Async\await;
386384

387-
function getSipPeers()
385+
function getSipPeers(): array
388386
{
389387
$factory = new Clue\React\Ami\Factory();
390388

@@ -398,11 +396,13 @@ function getSipPeers()
398396
return $ret;
399397
});
400398

401-
return Block\await($promise, Loop::get(), 5.0);
399+
return await($promise);
402400
}
403401
```
404402

405-
Refer to [clue/reactphp-block](https://github.com/clue/reactphp-block#readme) for more details.
403+
This is made possible thanks to fibers available in PHP 8.1+ and our
404+
compatibility API that also works on all supported PHP versions.
405+
Please refer to [reactphp/async](https://github.com/reactphp/async#readme) for more details.
406406

407407
### Message
408408

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"react/socket": "^1.14"
1919
},
2020
"require-dev": {
21-
"clue/block-react": "^1.5",
22-
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"
21+
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36",
22+
"react/async": "^4 || ^3 || ^2"
2323
},
2424
"autoload": {
2525
"psr-4": {

tests/FunctionalTest.php

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace Clue\Tests\React\Ami;
44

5-
use Clue\React\Ami\Factory;
6-
use Clue\React\Ami\Client;
75
use Clue\React\Ami\ActionSender;
8-
use Clue\React\Block;
6+
use Clue\React\Ami\Client;
7+
use Clue\React\Ami\Factory;
8+
use Clue\React\Ami\Protocol\Response;
9+
use React\EventLoop\Loop;
910
use React\Promise\PromiseInterface;
1011

1112
class FunctionalTest extends TestCase
@@ -19,7 +20,6 @@ class FunctionalTest extends TestCase
1920
public static function setUpLoopBeforeClass()
2021
{
2122
self::$address = getenv('LOGIN');
22-
self::$loop = \React\EventLoop\Factory::create();
2323
}
2424

2525
/**
@@ -34,10 +34,10 @@ public function setUpSkipTest()
3434

3535
public function testConnection()
3636
{
37-
$factory = new Factory(self::$loop);
37+
$factory = new Factory();
3838

39-
$client = $this->waitFor($factory->createClient(self::$address));
40-
/* @var $client Client */
39+
$client = \React\Async\await($factory->createClient(self::$address));
40+
assert($client instanceof Client);
4141

4242
$this->assertFalse($client->isBusy());
4343

@@ -52,7 +52,7 @@ public function testPing(Client $client)
5252
{
5353
$sender = new ActionSender($client);
5454

55-
$pong = $this->waitFor($sender->ping());
55+
$pong = \React\Async\await($sender->ping());
5656

5757
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $pong);
5858
}
@@ -64,7 +64,7 @@ public function testPing(Client $client)
6464
public function testInvalidCommandGetsRejected(Client $client)
6565
{
6666
$this->setExpectedException('Exception');
67-
$this->waitFor($client->request($client->createAction('Invalid')));
67+
\React\Async\await($client->request($client->createAction('Invalid')));
6868
}
6969

7070
/**
@@ -75,15 +75,14 @@ public function testActionSenderLogoffDisconnects(Client $client)
7575
{
7676
$sender = new ActionSender($client);
7777

78-
$ret = $this->waitFor($sender->logoff());
79-
80-
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $ret);
78+
$ret = \React\Async\await($sender->logoff());
79+
assert($ret instanceof Response);
8180

8281
$this->assertFalse($client->isBusy());
8382

8483
//$client->on('close', $this->expectCallableOnce());
8584

86-
self::$loop->run();
85+
Loop::run();
8786

8887
return $client;
8988
}
@@ -95,11 +94,6 @@ public function testActionSenderLogoffDisconnects(Client $client)
9594
public function testSendRejectedAfterClose(Client $client)
9695
{
9796
$this->setExpectedException('Exception');
98-
$this->waitFor($client->request($client->createAction('Ping')));
99-
}
100-
101-
private function waitFor(PromiseInterface $promise)
102-
{
103-
return Block\await($promise, self::$loop, 5.0);
97+
\React\Async\await($client->request($client->createAction('Ping')));
10498
}
10599
}

0 commit comments

Comments
 (0)