Skip to content

Commit 53dfbef

Browse files
authored
Merge pull request #58 from clue-labs/namespace-docs
Improve documentation to use fully-qualified function names
2 parents 848d45b + 42c337e commit 53dfbef

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function blockingExample()
6565
$request2 = $browser->get('http://www.google.co.uk/');
6666

6767
// keep the loop running (i.e. block) until the first response arrives
68-
$fasterResponse = Block\awaitAny(array($request1, $request2), $loop);
68+
$fasterResponse = Clue\React\Block\awaitAny(array($request1, $request2), $loop);
6969

7070
return $fasterResponse->getBody();
7171
}
@@ -76,18 +76,26 @@ function blockingExample()
7676
This lightweight library consists only of a few simple functions.
7777
All functions reside under the `Clue\React\Block` namespace.
7878

79-
The below examples assume you use an import statement similar to this:
79+
The below examples refer to all functions with their fully-qualified names like this:
8080

8181
```php
82-
use Clue\React\Block;
82+
Clue\React\Block\await(…);
83+
```
8384

84-
Block\await(…);
85+
As of PHP 5.6+ you can also import each required function into your code like this:
86+
87+
```php
88+
use function Clue\React\Block\await;
89+
90+
await(…);
8591
```
8692

87-
Alternatively, you can also refer to them with their fully-qualified name:
93+
Alternatively, you can also use an import statement similar to this:
8894

8995
```php
90-
\Clue\React\Block\await(…);
96+
use Clue\React\Block;
97+
98+
Block\await(…);
9199
```
92100

93101
### EventLoop
@@ -106,7 +114,7 @@ The `sleep($seconds, LoopInterface $loop): void` function can be used to
106114
wait/sleep for `$time` seconds.
107115

108116
```php
109-
Block\sleep(1.5, $loop);
117+
Clue\React\Block\sleep(1.5, $loop);
110118
```
111119

112120
This function will only return after the given `$time` has elapsed. In the
@@ -125,7 +133,7 @@ The `await(PromiseInterface $promise, LoopInterface $loop, ?float $timeout = nul
125133
block waiting for the given `$promise` to be fulfilled.
126134

127135
```php
128-
$result = Block\await($promise, $loop, $timeout);
136+
$result = Clue\React\Block\await($promise, $loop, $timeout);
129137
```
130138

131139
This function will only return after the given `$promise` has settled, i.e.
@@ -141,7 +149,7 @@ will throw an `UnexpectedValueException` instead.
141149

142150
```php
143151
try {
144-
$result = Block\await($promise, $loop);
152+
$result = Clue\React\Block\await($promise, $loop);
145153
// promise successfully fulfilled with $result
146154
echo 'Result: ' . $result;
147155
} catch (Exception $exception) {
@@ -171,7 +179,7 @@ $promises = array(
171179
$promise2
172180
);
173181

174-
$firstResult = Block\awaitAny($promises, $loop, $timeout);
182+
$firstResult = Clue\React\Block\awaitAny($promises, $loop, $timeout);
175183

176184
echo 'First result: ' . $firstResult;
177185
```
@@ -208,7 +216,7 @@ $promises = array(
208216
$promise2
209217
);
210218

211-
$allResults = Block\awaitAll($promises, $loop, $timeout);
219+
$allResults = Clue\React\Block\awaitAll($promises, $loop, $timeout);
212220

213221
echo 'First promise resolved with: ' . $allResults[0];
214222
```

examples/01-await.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use Clue\React\Block;
4-
53
require __DIR__ . '/../vendor/autoload.php';
64

75
/**
@@ -22,7 +20,7 @@ function requestHttp($url)
2220

2321
try {
2422
// keep the loop running (i.e. block) until the response arrives
25-
$result = Block\await($promise, $loop);
23+
$result = Clue\React\Block\await($promise, $loop);
2624

2725
// promise successfully fulfilled with $result
2826
return $result;

examples/02-await-any.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use Clue\React\Block;
4-
53
require __DIR__ . '/../vendor/autoload.php';
64

75
/**
@@ -26,7 +24,7 @@ function requestHttpFastestOfMultiple($url1, $url2)
2624

2725
try {
2826
// keep the loop running (i.e. block) until the first response arrives
29-
$fasterResponse = Block\awaitAny($promises, $loop);
27+
$fasterResponse = Clue\React\Block\awaitAny($promises, $loop);
3028

3129
// promise successfully fulfilled with $fasterResponse
3230
return $fasterResponse;

examples/03-await-all.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use Clue\React\Block;
4-
53
require __DIR__ . '/../vendor/autoload.php';
64

75
/**
@@ -26,7 +24,7 @@ function requestHttpMultiple($url1, $url2)
2624

2725
try {
2826
// keep the loop running (i.e. block) until all responses arrive
29-
$allResults = Block\awaitAll($promises, $loop);
27+
$allResults = Clue\React\Block\awaitAll($promises, $loop);
3028

3129
// promise successfully fulfilled with $allResults
3230
return $allResults;

src/functions.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Wait/sleep for `$time` seconds.
1616
*
1717
* ```php
18-
* Block\sleep(1.5, $loop);
18+
* Clue\React\Block\sleep(1.5, $loop);
1919
* ```
2020
*
2121
* This function will only return after the given `$time` has elapsed. In the
@@ -41,7 +41,7 @@ function sleep($time, LoopInterface $loop)
4141
* Block waiting for the given `$promise` to be fulfilled.
4242
*
4343
* ```php
44-
* $result = Block\await($promise, $loop, $timeout);
44+
* $result = Clue\React\Block\await($promise, $loop, $timeout);
4545
* ```
4646
*
4747
* This function will only return after the given `$promise` has settled, i.e.
@@ -57,7 +57,7 @@ function sleep($time, LoopInterface $loop)
5757
*
5858
* ```php
5959
* try {
60-
* $result = Block\await($promise, $loop);
60+
* $result = Clue\React\Block\await($promise, $loop);
6161
* // promise successfully fulfilled with $result
6262
* echo 'Result: ' . $result;
6363
* } catch (Exception $exception) {
@@ -144,7 +144,7 @@ function ($error) use (&$exception, &$rejected, &$wait, $loop) {
144144
* $promise2
145145
* );
146146
*
147-
* $firstResult = Block\awaitAny($promises, $loop, $timeout);
147+
* $firstResult = Clue\React\Block\awaitAny($promises, $loop, $timeout);
148148
*
149149
* echo 'First result: ' . $firstResult;
150150
* ```
@@ -224,7 +224,7 @@ function awaitAny(array $promises, LoopInterface $loop, $timeout = null)
224224
* $promise2
225225
* );
226226
*
227-
* $allResults = Block\awaitAll($promises, $loop, $timeout);
227+
* $allResults = Clue\React\Block\awaitAll($promises, $loop, $timeout);
228228
*
229229
* echo 'First promise resolved with: ' . $allResults[0];
230230
* ```

0 commit comments

Comments
 (0)