Skip to content

Commit 3422dad

Browse files
committed
Remove deprecated $timeout argument
1 parent 97770fa commit 3422dad

File tree

4 files changed

+3
-149
lines changed

4 files changed

+3
-149
lines changed

README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Async\await(…);
5454

5555
### await()
5656

57-
The `await(PromiseInterface $promise, ?LoopInterface $loop = null, ?float $timeout = null): mixed` function can be used to
57+
The `await(PromiseInterface $promise, ?LoopInterface $loop = null): mixed` function can be used to
5858
block waiting for the given `$promise` to be fulfilled.
5959

6060
```php
@@ -89,17 +89,6 @@ use the [default loop](https://github.com/reactphp/event-loop#loop). This value
8989
SHOULD NOT be given unless you're sure you want to explicitly use a given event
9090
loop instance.
9191

92-
If no `$timeout` argument is given and the promise stays pending, then this
93-
will potentially wait/block forever until the promise is settled. To avoid
94-
this, API authors creating promises are expected to provide means to
95-
configure a timeout for the promise instead. For more details, see also the
96-
[`timeout()` function](https://github.com/reactphp/promise-timer#timeout).
97-
98-
If the deprecated `$timeout` argument is given and the promise is still pending once the
99-
timeout triggers, this will `cancel()` the promise and throw a `TimeoutException`.
100-
This implies that if you pass a really small (or negative) value, it will still
101-
start a timer and will thus trigger at the earliest possible time in the future.
102-
10392
Note that this function will assume control over the event loop. Internally, it
10493
will actually `run()` the loop until the promise settles and then calls `stop()` to
10594
terminate execution of the loop. This means this function is more suited for

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
"require": {
2929
"php": ">=5.3.2",
3030
"react/event-loop": "^1.2",
31-
"react/promise": "^2.8 || ^1.2.1",
32-
"react/promise-timer": "^1.5"
31+
"react/promise": "^2.8 || ^1.2.1"
3332
},
3433
"require-dev": {
3534
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"

src/functions.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use React\EventLoop\LoopInterface;
77
use React\Promise\Deferred;
88
use React\Promise\PromiseInterface;
9-
use React\Promise\Timer;
109

1110
/**
1211
* Block waiting for the given `$promise` to be fulfilled.
@@ -43,17 +42,6 @@
4342
* SHOULD NOT be given unless you're sure you want to explicitly use a given event
4443
* loop instance.
4544
*
46-
* If no `$timeout` argument is given and the promise stays pending, then this
47-
* will potentially wait/block forever until the promise is settled. To avoid
48-
* this, API authors creating promises are expected to provide means to
49-
* configure a timeout for the promise instead. For more details, see also the
50-
* [`timeout()` function](https://github.com/reactphp/promise-timer#timeout).
51-
*
52-
* If the deprecated `$timeout` argument is given and the promise is still pending once the
53-
* timeout triggers, this will `cancel()` the promise and throw a `TimeoutException`.
54-
* This implies that if you pass a really small (or negative) value, it will still
55-
* start a timer and will thus trigger at the earliest possible time in the future.
56-
*
5745
* Note that this function will assume control over the event loop. Internally, it
5846
* will actually `run()` the loop until the promise settles and then calls `stop()` to
5947
* terminate execution of the loop. This means this function is more suited for
@@ -63,23 +51,17 @@
6351
*
6452
* @param PromiseInterface $promise
6553
* @param ?LoopInterface $loop
66-
* @param ?float $timeout [deprecated] (optional) maximum timeout in seconds or null=wait forever
6754
* @return mixed returns whatever the promise resolves to
6855
* @throws \Exception when the promise is rejected
69-
* @throws \React\Promise\Timer\TimeoutException if the $timeout is given and triggers
7056
*/
71-
function await(PromiseInterface $promise, LoopInterface $loop = null, $timeout = null)
57+
function await(PromiseInterface $promise, LoopInterface $loop = null)
7258
{
7359
$wait = true;
7460
$resolved = null;
7561
$exception = null;
7662
$rejected = false;
7763
$loop = $loop ?: Loop::get();
7864

79-
if ($timeout !== null) {
80-
$promise = Timer\timeout($promise, $timeout, $loop);
81-
}
82-
8365
$promise->then(
8466
function ($c) use (&$resolved, &$wait, $loop) {
8567
$resolved = $c;

tests/AwaitTest.php

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use React\EventLoop\Loop;
77
use React\Promise;
88
use React\Promise\Deferred;
9-
use React\Promise\Timer\TimeoutException;
109

1110
class AwaitTest extends TestCase
1211
{
@@ -93,40 +92,6 @@ public function testAwaitOneInterrupted()
9392
$this->assertEquals(2, React\Async\await($promise, $this->loop));
9493
}
9594

96-
public function testAwaitOncePendingWillThrowOnTimeout()
97-
{
98-
$promise = new Promise\Promise(function () { });
99-
100-
$this->setExpectedException('React\Promise\Timer\TimeoutException');
101-
React\Async\await($promise, $this->loop, 0.001);
102-
}
103-
104-
public function testAwaitOncePendingWillThrowAndCallCancellerOnTimeout()
105-
{
106-
$cancelled = false;
107-
$promise = new Promise\Promise(function () { }, function () use (&$cancelled) {
108-
$cancelled = true;
109-
});
110-
111-
try {
112-
React\Async\await($promise, $this->loop, 0.001);
113-
} catch (TimeoutException $expected) {
114-
$this->assertTrue($cancelled);
115-
}
116-
}
117-
118-
public function testAwaitOnceWithTimeoutWillResolvemmediatelyAndCleanUpTimeout()
119-
{
120-
$promise = Promise\resolve(true);
121-
122-
$time = microtime(true);
123-
React\Async\await($promise, $this->loop, 5.0);
124-
$this->loop->run();
125-
$time = microtime(true) - $time;
126-
127-
$this->assertLessThan(0.1, $time);
128-
}
129-
13095
public function testAwaitOneResolvesShouldNotCreateAnyGarbageReferences()
13196
{
13297
if (class_exists('React\Promise\When') && PHP_VERSION_ID >= 50400) {
@@ -161,25 +126,6 @@ public function testAwaitOneRejectedShouldNotCreateAnyGarbageReferences()
161126
$this->assertEquals(0, gc_collect_cycles());
162127
}
163128

164-
public function testAwaitOneRejectedWithTimeoutShouldNotCreateAnyGarbageReferences()
165-
{
166-
if (class_exists('React\Promise\When') && PHP_VERSION_ID >= 50400) {
167-
$this->markTestSkipped('Not supported on legacy Promise v1 API with PHP 5.4+');
168-
}
169-
170-
gc_collect_cycles();
171-
172-
$promise = Promise\reject(new \RuntimeException());
173-
try {
174-
React\Async\await($promise, $this->loop, 0.001);
175-
} catch (\Exception $e) {
176-
// no-op
177-
}
178-
unset($promise, $e);
179-
180-
$this->assertEquals(0, gc_collect_cycles());
181-
}
182-
183129
public function testAwaitNullValueShouldNotCreateAnyGarbageReferences()
184130
{
185131
if (!interface_exists('React\Promise\CancellablePromiseInterface')) {
@@ -203,68 +149,6 @@ public function testAwaitNullValueShouldNotCreateAnyGarbageReferences()
203149
$this->assertEquals(0, gc_collect_cycles());
204150
}
205151

206-
/**
207-
* @requires PHP 7
208-
*/
209-
public function testAwaitPendingPromiseWithTimeoutAndCancellerShouldNotCreateAnyGarbageReferences()
210-
{
211-
if (class_exists('React\Promise\When')) {
212-
$this->markTestSkipped('Not supported on legacy Promise v1 API');
213-
}
214-
215-
gc_collect_cycles();
216-
217-
$promise = new \React\Promise\Promise(function () { }, function () {
218-
throw new \RuntimeException();
219-
});
220-
try {
221-
React\Async\await($promise, $this->loop, 0.001);
222-
} catch (\Exception $e) {
223-
// no-op
224-
}
225-
unset($promise, $e);
226-
227-
$this->assertEquals(0, gc_collect_cycles());
228-
}
229-
230-
/**
231-
* @requires PHP 7
232-
*/
233-
public function testAwaitPendingPromiseWithTimeoutAndWithoutCancellerShouldNotCreateAnyGarbageReferences()
234-
{
235-
gc_collect_cycles();
236-
237-
$promise = new \React\Promise\Promise(function () { });
238-
try {
239-
React\Async\await($promise, $this->loop, 0.001);
240-
} catch (\Exception $e) {
241-
// no-op
242-
}
243-
unset($promise, $e);
244-
245-
$this->assertEquals(0, gc_collect_cycles());
246-
}
247-
248-
/**
249-
* @requires PHP 7
250-
*/
251-
public function testAwaitPendingPromiseWithTimeoutAndNoOpCancellerShouldNotCreateAnyGarbageReferences()
252-
{
253-
gc_collect_cycles();
254-
255-
$promise = new \React\Promise\Promise(function () { }, function () {
256-
// no-op
257-
});
258-
try {
259-
React\Async\await($promise, $this->loop, 0.001);
260-
} catch (\Exception $e) {
261-
// no-op
262-
}
263-
unset($promise, $e);
264-
265-
$this->assertEquals(0, gc_collect_cycles());
266-
}
267-
268152
protected function createPromiseResolved($value = null, $delay = 0.01)
269153
{
270154
$deferred = new Deferred();

0 commit comments

Comments
 (0)