Lines Matching refs:promise

7 [![CI status](https://github.com/reactphp/promise/actions/workflows/ci.yml/badge.svg?branch=2.x)](https://github.com/reactphp/promise/actions)
8 [![installs on Packagist](https://img.shields.io/packagist/dt/react/promise?color=blue&label=installs%20on%20Packagist)](https://packagist.org/packages/react/promise)
16 * [Promise](#promise-1)
19 * [Deferred::promise()](#deferredpromise)
32 * [Promise](#promise-2)
48 * [How promise forwarding works](#how-promise-forwarding-works)
64 It also provides several other useful promise-related concepts, such as joining
82 the result of that computation. Thus, each deferred has a promise that acts as
91 promise and resolver parts.
96 $promise = $deferred->promise();
103 The `promise` method returns the promise of the deferred.
110 See [Promise](#promise-2) for more information.
112 #### Deferred::promise()
115 $promise = $deferred->promise();
118 Returns the promise of the deferred, which you can hand out to others while
127 Resolves the promise returned by `promise()`. All consumers are notified by
128 having `$onFulfilled` (which they registered via `$promise->then()`) called with
131 If `$value` itself is a promise, the promise will transition to the state of
132 this promise once it is resolved.
140 Rejects the promise returned by `promise()`, signalling that the deferred's
143 `$promise->then()`) called with `$reason`.
145 If `$reason` itself is a promise, the promise will be rejected with the outcome
146 of this promise regardless whether it fulfills or rejects.
160 `$promise->then()`) called with `$update`.
164 The promise interface provides the common interface for all promise
167 A promise represents an eventual outcome, which is either fulfillment (success)
170 Once in the fulfilled or rejected state, a promise becomes immutable.
175 * [Promise](#promise-2)
183 $transformedPromise = $promise->then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null);
186 Transforms a promise's value by applying a function to the promise's fulfillment
187 or rejection value. Returns a new promise for the transformed result.
190 with a promise (all parameters are optional):
192 * `$onFulfilled` will be invoked once the promise is fulfilled and passed
194 * `$onRejected` will be invoked once the promise is rejected and passed the
196 * `$onProgress` (deprecated) will be invoked whenever the producer of the promise
200 It returns a new promise that will fulfill with the return value of either
204 A promise makes the following guarantees about handlers registered in
215 * [resolve()](#resolve) - Creating a resolved promise
216 * [reject()](#reject) - Creating a rejected promise
227 * [Promise](#promise-1)
235 $promise->done(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null);
238 Consumes the promise's ultimate value if the promise fulfills, or handles the
242 return a rejected promise.
255 $promise->otherwise(callable $onRejected);
258 Registers a rejection handler for promise. It is a shortcut for:
261 $promise->then(null, $onRejected);
268 $promise
281 $newPromise = $promise->always(callable $onFulfilledOrRejected);
284 Allows you to execute "cleanup" type tasks in a promise chain.
287 when the promise is either fulfilled or rejected.
289 * If `$promise` fulfills, and `$onFulfilledOrRejected` returns successfully,
290 `$newPromise` will fulfill with the same value as `$promise`.
291 * If `$promise` fulfills, and `$onFulfilledOrRejected` throws or returns a
292 rejected promise, `$newPromise` will reject with the thrown exception or
293 rejected promise's reason.
294 * If `$promise` rejects, and `$onFulfilledOrRejected` returns successfully,
295 `$newPromise` will reject with the same reason as `$promise`.
296 * If `$promise` rejects, and `$onFulfilledOrRejected` throws or returns a
297 rejected promise, `$newPromise` will reject with the thrown exception or
298 rejected promise's reason.
316 Similar asynchronous code (with `doSomething()` that returns a promise) can be
330 $promise->progress(callable $onProgress);
333 Registers a handler for progress updates from promise. It is a shortcut for:
336 $promise->then(null, null, $onProgress);
341 A cancellable promise provides a mechanism for consumers to notify the creator
342 of the promise that they are not longer interested in the result of an
348 $promise->cancel();
351 The `cancel()` method notifies the creator of the promise that there is no
354 Once a promise is settled (either fulfilled or rejected), calling `cancel()` on
355 a promise has no effect.
359 * [Promise](#promise-1)
366 Creates a promise whose state is controlled by the functions passed to
385 // Reject promise by throwing an exception
389 $promise = new React\Promise\Promise($resolver, $canceller);
392 The promise constructor receives a resolver function and an optional canceller
396 returned promise. Accepts either a non-promise value, or another promise.
397 When called with a non-promise value, fulfills promise with that value.
398 When called with another promise, e.g. `$resolve($otherPromise)`, promise's
400 * `$reject($reason)` - Function that rejects the promise. It is recommended to
402 * `$notify($update)` - Deprecated function that issues progress events for the promise.
404 If the resolver or canceller throw an exception, the promise will be rejected
408 once all consumers called the `cancel()` method of the promise.
414 Creates a already fulfilled promise.
417 $promise = React\Promise\FulfilledPromise($value);
420 Note, that `$value` **cannot** be a promise. It's recommended to use
427 Creates a already rejected promise.
430 $promise = React\Promise\RejectedPromise($reason);
433 Note, that `$reason` **cannot** be a promise. It's recommended to use
440 Creates a promise which will be lazily initialized by `$factory` once a consumer
449 return $deferred->promise();
452 $promise = new React\Promise\LazyPromise($factory);
455 $promise->then(function ($value) {
464 All functions working on promise collections (like `all()`, `race()`, `some()`
466 promise, all promises in the collection are cancelled. If the collection itself
467 is a promise which resolves to an array, this promise is also cancelled.
472 $promise = React\Promise\resolve(mixed $promiseOrValue);
475 Creates a promise for the supplied `$promiseOrValue`.
478 returned promise.
481 a trusted promise that follows the state of the thenable is returned.
483 If `$promiseOrValue` is a promise, it will be returned as is.
485 Note: The promise returned is always a promise implementing
487 promise which only implements [PromiseInterface](#promiseinterface), this
488 promise will be assimilated to a extended promise following `$promiseOrValue`.
493 $promise = React\Promise\reject(mixed $promiseOrValue);
496 Creates a rejected promise for the supplied `$promiseOrValue`.
499 returned promise.
501 If `$promiseOrValue` is a promise, its completion value will be the rejected
502 value of the returned promise.
504 This can be useful in situations where you need to reject a promise without
506 the value of another promise.
511 $promise = React\Promise\all(array|React\Promise\PromiseInterface $promisesOrValues);
514 Returns a promise that will resolve only once all the items in
515 `$promisesOrValues` have resolved. The resolution value of the returned promise
522 $promise = React\Promise\race(array|React\Promise\PromiseInterface $promisesOrValues);
525 Initiates a competitive race that allows one winner. Returns a promise which is
526 resolved in the same way the first settled promise resolves.
531 $promise = React\Promise\any(array|React\Promise\PromiseInterface $promisesOrValues);
534 Returns a promise that will resolve when any one of the items in
535 `$promisesOrValues` resolves. The resolution value of the returned promise
538 The returned promise will only reject if *all* items in `$promisesOrValues` are
541 The returned promise will also reject with a `React\Promise\Exception\LengthException`
547 $promise = React\Promise\some(array|React\Promise\PromiseInterface $promisesOrValues, integer $howMany);
550 Returns a promise that will resolve when `$howMany` of the supplied items in
551 `$promisesOrValues` resolve. The resolution value of the returned promise
555 The returned promise will reject if it becomes impossible for `$howMany` items
560 The returned promise will also reject with a `React\Promise\Exception\LengthException`
566 $promise = React\Promise\map(array|React\Promise\PromiseInterface $promisesOrValues, callable $mapFunc);
570 promises and/or values, and `$mapFunc` may return either a value or a promise.
573 value of a promise or value in `$promisesOrValues`.
578 $promise = React\Promise\reduce(array|React\Promise\PromiseInterface $promisesOrValues, callable $reduceFunc , $initialValue = null);
583 promise, *and* `$initialValue` may be a promise or a value for the starting
589 that provide a promise. `React\Promise\Deferred` implements it, but since it
611 // Return the promise
612 return $deferred->promise();
629 ### How promise forwarding works
632 These examples are contrived, of course, and in real usage, promise chains will
638 Resolved promises forward resolution values to the next promise.
639 The first promise, `$deferred->promise()`, will resolve with the value passed
642 Each call to `then()` returns a new promise that will resolve with the return
643 value of the previous handler. This creates a promise "pipeline".
648 $deferred->promise()
651 // and returns a *new promise* for $x + 1
681 Similarly, when you handle a rejected promise, to propagate the rejection,
682 "rethrow" it by either returning a rejected promise, or actually throwing
683 (since promise translates thrown exceptions into rejections)
688 $deferred->promise()
717 $deferred->promise()
759 $deferred->promise()
774 Either return your promise, or call done() on it.
779 The intent of `then()` is to transform a promise's value and to pass or return
780 a new promise for the transformed value along to other parts of your code.
782 The intent of `done()` is to consume a promise's value, transferring
787 by the promise machinery and used to reject the promise returned by `then()`.
811 // Here we provide no rejection handler. If the promise returned has been
853 composer require react/promise:^2.11