Skip to content

Commit fa8d6fc

Browse files
committed
Deprecate $timeout argument for await*() functions
1 parent 53dfbef commit fa8d6fc

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ The `await(PromiseInterface $promise, LoopInterface $loop, ?float $timeout = nul
133133
block waiting for the given `$promise` to be fulfilled.
134134

135135
```php
136-
$result = Clue\React\Block\await($promise, $loop, $timeout);
136+
$result = Clue\React\Block\await($promise, $loop);
137137
```
138138

139139
This function will only return after the given `$promise` has settled, i.e.
@@ -161,9 +161,12 @@ try {
161161
See also the [examples](examples/).
162162

163163
If no `$timeout` argument is given and the promise stays pending, then this
164-
will potentially wait/block forever until the promise is settled.
164+
will potentially wait/block forever until the promise is settled. To avoid
165+
this, API authors creating promises are expected to provide means to
166+
configure a timeout for the promise instead. For more details, see also the
167+
[`timeout()` function](https://github.com/reactphp/promise-timer#timeout).
165168

166-
If a `$timeout` argument is given and the promise is still pending once the
169+
If the deprecated `$timeout` argument is given and the promise is still pending once the
167170
timeout triggers, this will `cancel()` the promise and throw a `TimeoutException`.
168171
This implies that if you pass a really small (or negative) value, it will still
169172
start a timer and will thus trigger at the earliest possible time in the future.
@@ -179,7 +182,7 @@ $promises = array(
179182
$promise2
180183
);
181184

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

184187
echo 'First result: ' . $firstResult;
185188
```
@@ -197,9 +200,12 @@ Once ALL promises reject, this function will fail and throw an `UnderflowExcepti
197200
Likewise, this will throw if an empty array of `$promises` is passed.
198201

199202
If no `$timeout` argument is given and ALL promises stay pending, then this
200-
will potentially wait/block forever until the promise is fulfilled.
203+
will potentially wait/block forever until the promise is fulfilled. To avoid
204+
this, API authors creating promises are expected to provide means to
205+
configure a timeout for the promise instead. For more details, see also the
206+
[`timeout()` function](https://github.com/reactphp/promise-timer#timeout).
201207

202-
If a `$timeout` argument is given and ANY promises are still pending once
208+
If the deprecated `$timeout` argument is given and ANY promises are still pending once
203209
the timeout triggers, this will `cancel()` all pending promises and throw a
204210
`TimeoutException`. This implies that if you pass a really small (or negative)
205211
value, it will still start a timer and will thus trigger at the earliest
@@ -216,7 +222,7 @@ $promises = array(
216222
$promise2
217223
);
218224

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

221227
echo 'First promise resolved with: ' . $allResults[0];
222228
```
@@ -237,9 +243,12 @@ and throw an `Exception`. If the promise did not reject with an `Exception`,
237243
then this function will throw an `UnexpectedValueException` instead.
238244

239245
If no `$timeout` argument is given and ANY promises stay pending, then this
240-
will potentially wait/block forever until the promise is fulfilled.
246+
will potentially wait/block forever until the promise is fulfilled. To avoid
247+
this, API authors creating promises are expected to provide means to
248+
configure a timeout for the promise instead. For more details, see also the
249+
[`timeout()` function](https://github.com/reactphp/promise-timer#timeout).
241250

242-
If a `$timeout` argument is given and ANY promises are still pending once
251+
If the deprecated `$timeout` argument is given and ANY promises are still pending once
243252
the timeout triggers, this will `cancel()` all pending promises and throw a
244253
`TimeoutException`. This implies that if you pass a really small (or negative)
245254
value, it will still start a timer and will thus trigger at the earliest

src/functions.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function sleep($time, LoopInterface $loop)
4141
* Block waiting for the given `$promise` to be fulfilled.
4242
*
4343
* ```php
44-
* $result = Clue\React\Block\await($promise, $loop, $timeout);
44+
* $result = Clue\React\Block\await($promise, $loop);
4545
* ```
4646
*
4747
* This function will only return after the given `$promise` has settled, i.e.
@@ -69,16 +69,19 @@ function sleep($time, LoopInterface $loop)
6969
* See also the [examples](../examples/).
7070
*
7171
* If no `$timeout` argument is given and the promise stays pending, then this
72-
* will potentially wait/block forever until the promise is settled.
72+
* will potentially wait/block forever until the promise is settled. To avoid
73+
* this, API authors creating promises are expected to provide means to
74+
* configure a timeout for the promise instead. For more details, see also the
75+
* [`timeout()` function](https://github.com/reactphp/promise-timer#timeout).
7376
*
74-
* If a `$timeout` argument is given and the promise is still pending once the
77+
* If the deprecated `$timeout` argument is given and the promise is still pending once the
7578
* timeout triggers, this will `cancel()` the promise and throw a `TimeoutException`.
7679
* This implies that if you pass a really small (or negative) value, it will still
7780
* start a timer and will thus trigger at the earliest possible time in the future.
7881
*
7982
* @param PromiseInterface $promise
8083
* @param LoopInterface $loop
81-
* @param null|float $timeout (optional) maximum timeout in seconds or null=wait forever
84+
* @param null|float $timeout [deprecated] (optional) maximum timeout in seconds or null=wait forever
8285
* @return mixed returns whatever the promise resolves to
8386
* @throws Exception when the promise is rejected
8487
* @throws TimeoutException if the $timeout is given and triggers
@@ -144,7 +147,7 @@ function ($error) use (&$exception, &$rejected, &$wait, $loop) {
144147
* $promise2
145148
* );
146149
*
147-
* $firstResult = Clue\React\Block\awaitAny($promises, $loop, $timeout);
150+
* $firstResult = Clue\React\Block\awaitAny($promises, $loop);
148151
*
149152
* echo 'First result: ' . $firstResult;
150153
* ```
@@ -162,17 +165,20 @@ function ($error) use (&$exception, &$rejected, &$wait, $loop) {
162165
* Likewise, this will throw if an empty array of `$promises` is passed.
163166
*
164167
* If no `$timeout` argument is given and ALL promises stay pending, then this
165-
* will potentially wait/block forever until the promise is fulfilled.
168+
* will potentially wait/block forever until the promise is fulfilled. To avoid
169+
* this, API authors creating promises are expected to provide means to
170+
* configure a timeout for the promise instead. For more details, see also the
171+
* [`timeout()` function](https://github.com/reactphp/promise-timer#timeout).
166172
*
167-
* If a `$timeout` argument is given and ANY promises are still pending once
173+
* If the deprecated `$timeout` argument is given and ANY promises are still pending once
168174
* the timeout triggers, this will `cancel()` all pending promises and throw a
169175
* `TimeoutException`. This implies that if you pass a really small (or negative)
170176
* value, it will still start a timer and will thus trigger at the earliest
171177
* possible time in the future.
172178
*
173179
* @param array $promises
174180
* @param LoopInterface $loop
175-
* @param null|float $timeout (optional) maximum timeout in seconds or null=wait forever
181+
* @param null|float $timeout [deprecated] (optional) maximum timeout in seconds or null=wait forever
176182
* @return mixed returns whatever the first promise resolves to
177183
* @throws Exception if ALL promises are rejected
178184
* @throws TimeoutException if the $timeout is given and triggers
@@ -224,7 +230,7 @@ function awaitAny(array $promises, LoopInterface $loop, $timeout = null)
224230
* $promise2
225231
* );
226232
*
227-
* $allResults = Clue\React\Block\awaitAll($promises, $loop, $timeout);
233+
* $allResults = Clue\React\Block\awaitAll($promises, $loop);
228234
*
229235
* echo 'First promise resolved with: ' . $allResults[0];
230236
* ```
@@ -244,17 +250,20 @@ function awaitAny(array $promises, LoopInterface $loop, $timeout = null)
244250
* then this function will throw an `UnexpectedValueException` instead.
245251
*
246252
* If no `$timeout` argument is given and ANY promises stay pending, then this
247-
* will potentially wait/block forever until the promise is fulfilled.
253+
* will potentially wait/block forever until the promise is fulfilled. To avoid
254+
* this, API authors creating promises are expected to provide means to
255+
* configure a timeout for the promise instead. For more details, see also the
256+
* [`timeout()` function](https://github.com/reactphp/promise-timer#timeout).
248257
*
249-
* If a `$timeout` argument is given and ANY promises are still pending once
258+
* If the deprecated `$timeout` argument is given and ANY promises are still pending once
250259
* the timeout triggers, this will `cancel()` all pending promises and throw a
251260
* `TimeoutException`. This implies that if you pass a really small (or negative)
252261
* value, it will still start a timer and will thus trigger at the earliest
253262
* possible time in the future.
254263
*
255264
* @param array $promises
256265
* @param LoopInterface $loop
257-
* @param null|float $timeout (optional) maximum timeout in seconds or null=wait forever
266+
* @param null|float $timeout [deprecated] (optional) maximum timeout in seconds or null=wait forever
258267
* @return array returns an array with whatever each promise resolves to
259268
* @throws Exception when ANY promise is rejected
260269
* @throws TimeoutException if the $timeout is given and triggers

0 commit comments

Comments
 (0)