Skip to content

Commit 109415f

Browse files
committed
Add When::lazy() to readme and changelog
1 parent 05abfc3 commit 109415f

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ CHANGELOG
55

66
* Trigger PHP errors when invalid callback is passed.
77
* Fully resolve rejection value before calling rejection handler.
8+
* Add When::lazy() to create lazy promises which will be initialized once a
9+
consumer calls the then() method.
810

911
* 1.0.3 (2012-11-17)
1012

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Table of Contents
2626
* [When::reduce()](#whenreduce)
2727
* [When::resolve()](#whenresolve)
2828
* [When::reject()](#whenreject)
29+
* [When::lazy()](#whenlazy)
2930
* [Promisor](#promisor)
3031
4. [Examples](#examples)
3132
* [How to use Deferred](#how-to-use-deferred)
@@ -282,6 +283,31 @@ This can be useful in situations where you need to reject a Promise without
282283
throwing an exception. For example, it allows you to propagate a rejection with
283284
the value of another Promise.
284285

286+
#### When::lazy()
287+
288+
``` php
289+
$promise = React\Promise\When::lazy(callable $factory);
290+
```
291+
292+
Creates a Promise which will be lazily initialized by `$factory` once a consumer
293+
calls the `then()` method.
294+
295+
```php
296+
$factory = function () {
297+
$deferred = new React\Promise\Deferred();
298+
299+
// Do some heavy stuff here and resolve the Deferred once completed
300+
301+
return $deferred->promise();
302+
};
303+
304+
$promise = React\Promise\When::lazy($factory);
305+
306+
// $factory will only be executed once we call then()
307+
$promise->then(function ($value) {
308+
});
309+
```
310+
285311
### Promisor
286312

287313
The `React\Promise\PromisorInterface` provides a common interface for objects

0 commit comments

Comments
 (0)