Skip to content

Commit 46c5b2b

Browse files
committed
More predictable cancellation by requiring cancellation support
Cancellation support has been backported from promise v2.1 to v1.2, so we can now rely on cancellation support being available for both major versions.
1 parent 8c423d5 commit 46c5b2b

File tree

5 files changed

+1
-70
lines changed

5 files changed

+1
-70
lines changed

README.md

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ If no cancellation handler is passed to the `Promise` constructor, then invoking
132132
its `cancel()` method it is effectively a NO-OP.
133133
This means that it may still be pending and can hence continue consuming resources.
134134

135-
> Note: If you're stuck on legacy versions (PHP 5.3), then this is also a NO-OP,
136-
as the Promise cancellation API is currently only available in
137-
[react/promise v2.1.0](https://github.com/reactphp/promise)
138-
which in turn requires PHP 5.4 or up.
139-
It is assumed that if you're actually still stuck on PHP 5.3, resource cleanup
140-
is likely one of your smaller problems.
141-
142135
For more details on the promise cancellation, please refer to the
143136
[Promise documentation](https://github.com/reactphp/promise#cancellablepromiseinterface).
144137

@@ -168,11 +161,6 @@ handling the `cancel()` call:
168161
The same happens if the input `$promise` does not register a
169162
[cancellation handler](#cancellation-handler).
170163

171-
> Note: If you're stuck on legacy versions (PHP 5.3), then the `cancel()` method
172-
is not available, as the Promise cancellation API is currently only available in
173-
[react/promise v2.1.0](https://github.com/reactphp/promise)
174-
which in turn requires PHP 5.4 or up.
175-
176164
#### Output cancellation
177165

178166
Similarily, you can also explicitly `cancel()` the resulting promise like this:
@@ -229,11 +217,6 @@ This means that while the resulting promise will still be rejected after the
229217
timeout, the underlying input `$promise` may still be pending and can hence
230218
continue consuming resources.
231219

232-
> Note: If you're stuck on legacy versions (PHP 5.3), then the `cancel()` method
233-
is not available, as the Promise cancellation API is currently only available in
234-
[react/promise v2.1.0](https://github.com/reactphp/promise)
235-
which in turn requires PHP 5.4 or up.
236-
237220
#### Collections
238221

239222
If you want to wait for multiple promises to resolve, you can use the normal promise primitives like this:
@@ -280,11 +263,6 @@ $timer->cancel();
280263

281264
This will abort the timer and *reject* with a `RuntimeException`.
282265

283-
> Note: If you're stuck on legacy versions (PHP 5.3), then the `cancel()` method
284-
is not available, as the Promise cancellation API is currently only available in
285-
[react/promise v2.1.0](https://github.com/reactphp/promise)
286-
which in turn requires PHP 5.4 or up.
287-
288266
### reject()
289267

290268
The `reject($time, LoopInterface $loop)` function can be used to create a new Promise
@@ -311,11 +289,6 @@ $timer->cancel();
311289

312290
This will abort the timer and *reject* with a `RuntimeException`.
313291

314-
> Note: If you're stuck on legacy versions (PHP 5.3), then the `cancel()` method
315-
is not available, as the Promise cancellation API is currently only available in
316-
[react/promise v2.1.0](https://github.com/reactphp/promise)
317-
which in turn requires PHP 5.4 or up.
318-
319292
### TimeoutException
320293

321294
The `TimeoutException` extends PHP's built-in `RuntimeException`.
@@ -335,12 +308,6 @@ The recommended way to install this library is [through composer](http://getcomp
335308
}
336309
```
337310

338-
> Note: If you're stuck on legacy versions (PHP 5.3), then the `cancel()` method
339-
is not available,
340-
as the Promise cancellation API is currently only available in
341-
[react/promise v2.1.0](https://github.com/reactphp/promise)
342-
which in turn requires PHP 5.4 or up.
343-
344311
## License
345312

346313
MIT

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"require": {
1818
"php": ">=5.3",
1919
"react/event-loop": "~0.4.0|~0.3.0",
20-
"react/promise": "~2.0|~1.1"
20+
"react/promise": "~2.1|~1.2"
2121
}
2222
}

tests/FunctionRejectTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ public function testCancelingPromiseWillRejectTimer()
2525
{
2626
$promise = Timer\reject(0.01, $this->loop);
2727

28-
if (!($promise instanceof CancellablePromiseInterface)) {
29-
$this->markTestSkipped('Outdated Promise API');
30-
}
31-
3228
$promise->cancel();
3329

3430
$this->expectPromiseRejected($promise);

tests/FunctionResolveTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ public function testCancellingPromiseWillCancelLoopTimer()
3838

3939
$promise = Timer\resolve(0.01, $loop);
4040

41-
if (!($promise instanceof CancellablePromiseInterface)) {
42-
$this->markTestSkipped('Outdated Promise API');
43-
}
44-
4541
$loop->expects($this->once())->method('cancelTimer')->with($this->equalTo($timer));
4642

4743
$promise->cancel();
@@ -51,10 +47,6 @@ public function testCancelingPromiseWillRejectTimer()
5147
{
5248
$promise = Timer\resolve(0.01, $this->loop);
5349

54-
if (!($promise instanceof CancellablePromiseInterface)) {
55-
$this->markTestSkipped('Outdated Promise API');
56-
}
57-
5850
$promise->cancel();
5951

6052
$this->expectPromiseRejected($promise);

tests/FunctionTimeoutTest.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ public function testPendingWillRejectOnTimeout()
6262

6363
public function testPendingCancellableWillBeCancelledOnTimeout()
6464
{
65-
if (!interface_exists('React\Promise\CancellablePromiseInterface', true)) {
66-
$this->markTestSkipped('Your (outdated?) Promise API does not support cancellable promises');
67-
}
68-
6965
$promise = $this->getMock('React\Promise\CancellablePromiseInterface');
7066
$promise->expects($this->once())->method('cancel');
7167

@@ -76,10 +72,6 @@ public function testPendingCancellableWillBeCancelledOnTimeout()
7672

7773
public function testCancelTimeoutWithoutCancellationhandlerWillNotCancelTimerAndWillNotReject()
7874
{
79-
if (!interface_exists('React\Promise\CancellablePromiseInterface', true)) {
80-
$this->markTestSkipped('Your (outdated?) Promise API does not support cancellable promises');
81-
}
82-
8375
$promise = new \React\Promise\Promise(function () { });
8476

8577
$loop = $this->getMock('React\EventLoop\LoopInterface');
@@ -97,10 +89,6 @@ public function testCancelTimeoutWithoutCancellationhandlerWillNotCancelTimerAnd
9789

9890
public function testCancelTimeoutWillCancelGivenPromise()
9991
{
100-
if (!interface_exists('React\Promise\CancellablePromiseInterface', true)) {
101-
$this->markTestSkipped('Your (outdated?) Promise API does not support cancellable promises');
102-
}
103-
10492
$promise = new \React\Promise\Promise(function () { }, $this->expectCallableOnce());
10593

10694
$timeout = Timer\timeout($promise, 0.01, $this->loop);
@@ -110,10 +98,6 @@ public function testCancelTimeoutWillCancelGivenPromise()
11098

11199
public function testCancelGivenPromiseWillReject()
112100
{
113-
if (!interface_exists('React\Promise\CancellablePromiseInterface', true)) {
114-
$this->markTestSkipped('Your (outdated?) Promise API does not support cancellable promises');
115-
}
116-
117101
$promise = new \React\Promise\Promise(function () { }, function ($resolve, $reject) { $reject(); });
118102

119103
$timeout = Timer\timeout($promise, 0.01, $this->loop);
@@ -126,10 +110,6 @@ public function testCancelGivenPromiseWillReject()
126110

127111
public function testCancelTimeoutWillRejectIfGivenPromiseWillReject()
128112
{
129-
if (!interface_exists('React\Promise\CancellablePromiseInterface', true)) {
130-
$this->markTestSkipped('Your (outdated?) Promise API does not support cancellable promises');
131-
}
132-
133113
$promise = new \React\Promise\Promise(function () { }, function ($resolve, $reject) { $reject(); });
134114

135115
$timeout = Timer\timeout($promise, 0.01, $this->loop);
@@ -142,10 +122,6 @@ public function testCancelTimeoutWillRejectIfGivenPromiseWillReject()
142122

143123
public function testCancelTimeoutWillResolveIfGivenPromiseWillResolve()
144124
{
145-
if (!interface_exists('React\Promise\CancellablePromiseInterface', true)) {
146-
$this->markTestSkipped('Your (outdated?) Promise API does not support cancellable promises');
147-
}
148-
149125
$promise = new \React\Promise\Promise(function () { }, function ($resolve, $reject) { $resolve(); });
150126

151127
$timeout = Timer\timeout($promise, 0.01, $this->loop);

0 commit comments

Comments
 (0)