21 $this->assertEquals(3, $finalValue);
36 $this->assertEquals(3, $finalValue);
55 $this->assertEquals(7, $finalValue);
73 $subPromise->fulfill(2);
76 $this->assertEquals(6, $finalValue);
92 $this->assertEquals(6, $finalValue);
108 $this->assertEquals(6, $finalValue);
118 }))->then(
function(
$result) use (&$realResult) {
125 $this->assertEquals(
'hi', $realResult);
135 }))->then(
function(
$result) use (&$realResult) {
137 $realResult =
'incorrect';
139 },
function($reason) use (&$realResult) {
141 $realResult = $reason;
146 $this->assertEquals(
'hi', $realResult);
176 $promise->otherwise(
function($reason) {
178 $this->assertEquals(
'foo', $reason);
179 throw new \Exception(
'hi');
181 })->
then(
function() use (&
$ok) {
185 },
function() use (&
$ok) {
191 $this->assertEquals(0,
$ok);
195 $this->assertEquals(1,
$ok);
211 $promise1->fulfill(1);
213 $this->assertEquals(0, $finalValue);
215 $promise2->fulfill(2);
217 $this->assertEquals([1, 2], $finalValue);
228 function(
$value) use (&$finalValue) {
232 function(
$value) use (&$finalValue) {
237 $promise1->reject(1);
239 $this->assertEquals(1, $finalValue);
240 $promise2->reject(2);
242 $this->assertEquals(1, $finalValue);
253 function(
$value) use (&$finalValue) {
257 function(
$value) use (&$finalValue) {
262 $promise1->reject(1);
264 $this->assertEquals(1, $finalValue);
265 $promise2->fulfill(2);
267 $this->assertEquals(1, $finalValue);
298 $promise->reject(
new \OutOfBoundsException(
'foo'));
302 $this->fail(
'We did not get the expected exception');
304 $this->assertInstanceOf(
'OutOfBoundsException', $e);
305 $this->assertEquals(
'foo', $e->getMessage());
318 $this->fail(
'We did not get the expected exception');
320 $this->assertInstanceOf(
'Exception', $e);
321 $this->assertEquals(
'foo', $e->getMessage());
334 $this->fail(
'We did not get the expected exception');
336 $this->assertInstanceOf(
'Exception', $e);
337 $this->assertEquals(
'Promise was rejected with reason of type: array', $e->getMessage());
testWaitRejectedNonScalar()
testAllRejectThenResolve()
An implementation of the Promise pattern.
then(callable $onFulfilled=null, callable $onRejected=null)
This method allows you to specify the callback that will be called after the promise has been fulfill...
$promise
This example shows demonstrates the Promise api.
static all(array $promises)
Deprecated.
nextTick(callable $cb)
Runs a function immediately at the next iteration of the loop.
testWaitWillNeverResolve()
testWaitRejectedException()