Skip to content

Commit ad8256d

Browse files
committed
Tweak readme
1 parent e4e0e9f commit ad8256d

1 file changed

Lines changed: 27 additions & 10 deletions

File tree

README.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,29 +76,37 @@ API
7676

7777
### Deferred
7878

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.
8082

8183
``` php
8284
$deferred = new React\Promise\Deferred();
8385

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();
8888
```
8989

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.
9293

9394
``` php
9495
$deferred = new React\Promise\Deferred();
9596

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);
98101
```
99102

100103
### Promise
101104

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+
102110
A Promise has a single method `then()` which registers new fulfilled, error and
103111
progress handlers with this Promise (all parameters are optional):
104112

@@ -139,8 +147,16 @@ the same call to `then()`:
139147
than once.
140148
3. `$progressHandler` may be called multiple times.
141149

150+
#### See also
151+
152+
* [When::resolve()](#whenresolve) - Creating a resolved Promise
153+
* [When::reject()](#whenreject) - Creating a rejected Promise
154+
142155
### Resolver
143156

157+
The Resolver represents the responsibility of fulfilling, rejecting and
158+
notifying the associated Promise.
159+
144160
A Resolver has 3 methods: `resolve()`, `reject()` and `progress()`:
145161

146162
``` php
@@ -182,7 +198,8 @@ $promise = React\Promise\When::all(array|React\Promise\PromiseInterface $promise
182198

183199
Returns a Promise that will resolve only once all the items in
184200
`$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`.
186203

187204
#### When::any()
188205

0 commit comments

Comments
 (0)