Skip to content

Commit bbeac80

Browse files
committed
Update README.md
1 parent c8f6280 commit bbeac80

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

README.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ The `await(PromiseInterface $promise, LoopInterface $loop)` method can be used t
9898
$result = Block\await($promise, $loop);
9999
```
100100

101+
Once the promise is resolved, this will return whatever the promise resolves to.
102+
103+
If the promises is being rejected, this will fail and throw an `Exception`.
104+
101105
```php
102106
try {
103107
$value = Block\await($promise, $loop);
@@ -119,25 +123,37 @@ $promises = array(
119123
$promise2
120124
);
121125

122-
$result = Block\awaitAny($promises, $loop);
126+
$firstResult = Block\awaitAny($promises, $loop);
127+
128+
echo 'First result: ' . $firstResult;
123129
```
124130

125-
Once the first promise is resolved, this will try to cancel() all
126-
* remaining promises and return whatever the first promise resolves to.
127-
*
128-
* If ALL promises fail to resolve, this will fail and throw an Exception.
131+
Once the first promise is resolved, this will try to `cancel()` all
132+
remaining promises and return whatever the first promise resolves to.
133+
134+
If ALL promises fail to resolve, this will fail and throw an `Exception`.
129135

130136
#### awaitAll()
131137

132138
The `awaitAll(array $promises, LoopInterface $loop)` method can be used to wait for ALL of the given promises to resolve.
133139

140+
```php
141+
$promises = array(
142+
$promise1,
143+
$promise2
144+
);
145+
146+
$allResults = Block\awaitAll($promises, $loop);
147+
148+
echo 'First promise resolved with: ' . $allResults[0];
149+
```
134150

135151
Once the last promise resolves, this will return an array with whatever
136-
* each promise resolves to. Array keys will be left intact, i.e. they can
137-
* be used to correlate the return array to the promises passed.
138-
*
139-
* If ANY promise fails to resolve, this will try to cancel() all
140-
* remaining promises and throw an Exception.
152+
each promise resolves to. Array keys will be left intact, i.e. they can
153+
be used to correlate the return array to the promises passed.
154+
155+
If ANY promise fails to resolve, this will try to `cancel()` all
156+
remaining promises and throw an `Exception`.
141157

142158
## Install
143159

0 commit comments

Comments
 (0)