Skip to content

Commit a469321

Browse files
committed
Implement dummy cancellation for settled promises
1 parent e1c80e8 commit a469321

5 files changed

Lines changed: 31 additions & 2 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@ further interest in the results of the operation.
504504
Once a promise is settled (either resolved or rejected), calling `cancel()` on
505505
a promise has no effect.
506506

507+
#### Implementations
508+
509+
* [FulfilledPromise](#fulfilledpromise)
510+
* [RejectedPromise](#rejectedpromise)
511+
507512
Examples
508513
--------
509514

src/React/Promise/FulfilledPromise.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace React\Promise;
44

5-
class FulfilledPromise implements PromiseInterface
5+
class FulfilledPromise implements PromiseInterface, CancellablePromiseInterface
66
{
77
private $result;
88

@@ -27,4 +27,8 @@ public function then($fulfilledHandler = null, $errorHandler = null, $progressHa
2727
return new RejectedPromise($exception);
2828
}
2929
}
30+
31+
public function cancel()
32+
{
33+
}
3034
}

src/React/Promise/RejectedPromise.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace React\Promise;
44

5-
class RejectedPromise implements PromiseInterface
5+
class RejectedPromise implements PromiseInterface, CancellablePromiseInterface
66
{
77
private $reason;
88

@@ -27,4 +27,8 @@ public function then($fulfilledHandler = null, $errorHandler = null, $progressHa
2727
return new RejectedPromise($exception);
2828
}
2929
}
30+
31+
public function cancel()
32+
{
33+
}
3034
}

tests/React/Promise/FulfilledPromiseTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,12 @@ public function shouldSwitchFromCallbacksToErrbacksWhenCallbackThrows()
140140
$mock2
141141
);
142142
}
143+
144+
/** @test */
145+
public function shouldNotBeAffectedByCancellation()
146+
{
147+
$p = new FulfilledPromise(1);
148+
$p->cancel();
149+
$p->then($this->expectCallableOnce());
150+
}
143151
}

tests/React/Promise/RejectedPromiseTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,12 @@ function ($val) {
145145
$mock
146146
);
147147
}
148+
149+
/** @test */
150+
public function shouldNotBeAffectedByCancellation()
151+
{
152+
$p = new RejectedPromise(1);
153+
$p->cancel();
154+
$p->then($this->expectCallableNever(), $this->expectCallableOnce());
155+
}
148156
}

0 commit comments

Comments
 (0)