File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 )
30314 . [ 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
282283throwing an exception. For example, it allows you to propagate a rejection with
283284the 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
287313The ` React\Promise\PromisorInterface ` provides a common interface for objects
You can’t perform that action at this time.
0 commit comments