ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\Event\Promise Namespace Reference

Data Structures

class  FunctionsTest
 
class  PromiseTest
 

Functions

 all (array $promises)
 This file contains a set of functions that are useful for dealing with the Promise object. More...
 
 race (array $promises)
 The race function returns a promise that resolves or rejects as soon as one of the promises in the argument resolves or rejects. More...
 
 resolve ($value)
 Returns a Promise that resolves with the given value. More...
 
 reject ($reason)
 Returns a Promise that will reject with the given reason. More...
 

Function Documentation

◆ all()

Sabre\Event\Promise\all ( array  $promises)

This file contains a set of functions that are useful for dealing with the Promise object.

Author
Evert Pot (http://evertpot.com/) @license http://sabre.io/license/ Modified BSD License This function takes an array of Promises, and returns a Promise that resolves when all of the given arguments have resolved.

The returned Promise will resolve with a value that's an array of all the values the given promises have been resolved with.

This array will be in the exact same order as the array of input promises.

If any of the given Promises fails, the returned promise will immidiately fail with the first Promise that fails, and its reason.

Parameters
Promise[]$promises
Returns
Promise

Definition at line 32 of file functions.php.

32 {
33
34 return new Promise(function($success, $fail) use ($promises) {
35
36 $successCount = 0;
37 $completeResult = [];
38
39 foreach ($promises as $promiseIndex => $subPromise) {
40
41 $subPromise->then(
42 function($result) use ($promiseIndex, &$completeResult, &$successCount, $success, $promises) {
43 $completeResult[$promiseIndex] = $result;
44 $successCount++;
45 if ($successCount === count($promises)) {
46 $success($completeResult);
47 }
48 return $result;
49 }
50 )->error(
51 function($reason) use ($fail) {
52 $fail($reason);
53 }
54 );
55
56 }
57 });
58
59}
$result
$success
Definition: Utf8Test.php:86
An implementation of the Promise pattern.
Definition: Promise.php:23
error($a_errmsg)
set error message @access public

References $result, $success, and Sabre\Event\Promise\error().

Referenced by Slim\Http\Headers\all(), ilPCTable\importHtml(), Slim\Handlers\NotFound\renderHtmlNotFoundOutput(), Sabre\VObject\Parser\XmlTest\testRFC6321Example2(), and Sabre\DAVACL\Xml\Property\SupportedPrivilegeSetTest\testToHtml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race()

Sabre\Event\Promise\race ( array  $promises)

The race function returns a promise that resolves or rejects as soon as one of the promises in the argument resolves or rejects.

The returned promise will resolve or reject with the value or reason of that first promise.

Parameters
Promise[]$promises
Returns
Promise

Definition at line 71 of file functions.php.

71 {
72
73 return new Promise(function($success, $fail) use ($promises) {
74
75 $alreadyDone = false;
76 foreach ($promises as $promise) {
77
78 $promise->then(
79 function($result) use ($success, &$alreadyDone) {
80 if ($alreadyDone) {
81 return;
82 }
83 $alreadyDone = true;
85 },
86 function($reason) use ($fail, &$alreadyDone) {
87 if ($alreadyDone) {
88 return;
89 }
90 $alreadyDone = true;
91 $fail($reason);
92 }
93 );
94
95 }
96
97 });
98
99}
$promise
This example shows demonstrates the Promise api.
Definition: promise.php:16

References $promise, $result, and $success.

Referenced by Sabre\Event\Promise\FunctionsTest\testRace(), Sabre\Event\PromiseTest\testRace(), Sabre\Event\Promise\FunctionsTest\testRaceReject(), and Sabre\Event\PromiseTest\testRaceReject().

+ Here is the caller graph for this function:

◆ reject()

Sabre\Event\Promise\reject (   $reason)

Returns a Promise that will reject with the given reason.

Parameters
mixed$reason
Returns
Promise

Definition at line 129 of file functions.php.

129 {
130
131 $promise = new Promise();
132 $promise->reject($reason);
133 return $promise;
134
135}

References $promise.

◆ resolve()

Sabre\Event\Promise\resolve (   $value)

Returns a Promise that resolves with the given value.

If the value is a promise, the returned promise will attach itself to that promise and eventually get the same state as the followed promise.

Parameters
mixed$value
Returns
Promise

Definition at line 111 of file functions.php.

111 {
112
113 if ($value instanceof Promise) {
114 return $value->then();
115 } else {
116 $promise = new Promise();
117 $promise->fulfill($value);
118 return $promise;
119 }
120
121}

References $promise, and Sabre\Event\Promise\$value.

Referenced by Sabre\HTTP\Client\send(), Sabre\Event\Promise\FunctionsTest\testResolve(), Sabre\Event\Promise\FunctionsTest\testResolvePromise(), Sabre\Xml\Element\Uri\xmlDeserialize(), and Sabre\Xml\Element\Uri\xmlSerialize().

+ Here is the caller graph for this function: