|
76 | 76 |
|
77 | 77 | ### Deferred |
78 | 78 |
|
79 | | -A Deferred has the full Promise + Resolver API: |
| 79 | +A deferred represents an operation whose resolution is pending. It has separate |
| 80 | +Promise and Resolver parts that can be safely given out to separate groups of |
| 81 | +consumers and producers to allow safe, one-way communication. |
80 | 82 |
|
81 | 83 | ``` php |
82 | 84 | $deferred = new React\Promise\Deferred(); |
83 | 85 |
|
84 | | -$deferred->then(callable $fulfilledHandler = null, callable $errorHandler = null, callable $progressHandler = null); |
85 | | -$deferred->resolve(mixed $promiseOrValue = null); |
86 | | -$deferred->reject(mixed $reason = null); |
87 | | -$deferred->progress(mixed $update = null); |
| 86 | +$promise = $deferred->promise(); |
| 87 | +$resolver = $deferred->resolver(); |
88 | 88 | ``` |
89 | 89 |
|
90 | | -It can also hand out separate Promise and Resolver parts that can be safely |
91 | | -given out to calling code: |
| 90 | +Although a Deferred has the full Promise + Resolver API, this should be used for |
| 91 | +convenience only by the creator of the deferred. Only the promise and resolver |
| 92 | +should be given to consumers and producers. |
92 | 93 |
|
93 | 94 | ``` php |
94 | 95 | $deferred = new React\Promise\Deferred(); |
95 | 96 |
|
96 | | -$promise = $deferred->promise(); |
97 | | -$resolver = $deferred->resolver(); |
| 97 | +$deferred->then(callable $fulfilledHandler = null, callable $errorHandler = null, callable $progressHandler = null); |
| 98 | +$deferred->resolve(mixed $promiseOrValue = null); |
| 99 | +$deferred->reject(mixed $reason = null); |
| 100 | +$deferred->progress(mixed $update = null); |
98 | 101 | ``` |
99 | 102 |
|
100 | 103 | ### Promise |
101 | 104 |
|
| 105 | +The Promise represents the eventual outcome, which is either fulfillment |
| 106 | +(success) and an associated value, or rejection (failure) and an associated |
| 107 | +reason. The Promise provides mechanisms for arranging to call a function on its |
| 108 | +value or reason, and produces a new promise for the result. |
| 109 | + |
102 | 110 | A Promise has a single method `then()` which registers new fulfilled, error and |
103 | 111 | progress handlers with this Promise (all parameters are optional): |
104 | 112 |
|
@@ -139,8 +147,16 @@ the same call to `then()`: |
139 | 147 | than once. |
140 | 148 | 3. `$progressHandler` may be called multiple times. |
141 | 149 |
|
| 150 | +#### See also |
| 151 | + |
| 152 | +* [When::resolve()](#whenresolve) - Creating a resolved Promise |
| 153 | +* [When::reject()](#whenreject) - Creating a rejected Promise |
| 154 | + |
142 | 155 | ### Resolver |
143 | 156 |
|
| 157 | +The Resolver represents the responsibility of fulfilling, rejecting and |
| 158 | +notifying the associated Promise. |
| 159 | + |
144 | 160 | A Resolver has 3 methods: `resolve()`, `reject()` and `progress()`: |
145 | 161 |
|
146 | 162 | ``` php |
@@ -182,7 +198,8 @@ $promise = React\Promise\When::all(array|React\Promise\PromiseInterface $promise |
182 | 198 |
|
183 | 199 | Returns a Promise that will resolve only once all the items in |
184 | 200 | `$promisesOrValues` have resolved. The resolution value of the returned Promise |
185 | | -will be an array containing the resolution values of each of the input array. |
| 201 | +will be an array containing the resolution values of each of the items in |
| 202 | +`$promisesOrValues`. |
186 | 203 |
|
187 | 204 | #### When::any() |
188 | 205 |
|
|
0 commit comments