Promise
=======
A lightweight implementation of
[CommonJS Promises/A](http://wiki.commonjs.org/wiki/Promises/A) for PHP.
[![CI status](https://github.com/reactphp/promise/workflows/CI/badge.svg?branch=2.x)](https://github.com/reactphp/promise/actions)
Table of Contents
-----------------
1. [Introduction](#introduction)
2. [Concepts](#concepts)
* [Deferred](#deferred)
* [Promise](#promise-1)
3. [API](#api)
* [Deferred](#deferred-1)
* [Deferred::promise()](#deferredpromise)
* [Deferred::resolve()](#deferredresolve)
* [Deferred::reject()](#deferredreject)
* [Deferred::notify()](#deferrednotify)
* [PromiseInterface](#promiseinterface)
* [PromiseInterface::then()](#promiseinterfacethen)
* [ExtendedPromiseInterface](#extendedpromiseinterface)
* [ExtendedPromiseInterface::done()](#extendedpromiseinterfacedone)
* [ExtendedPromiseInterface::otherwise()](#extendedpromiseinterfaceotherwise)
* [ExtendedPromiseInterface::always()](#extendedpromiseinterfacealways)
* [ExtendedPromiseInterface::progress()](#extendedpromiseinterfaceprogress)
* [CancellablePromiseInterface](#cancellablepromiseinterface)
* [CancellablePromiseInterface::cancel()](#cancellablepromiseinterfacecancel)
* [Promise](#promise-2)
* [FulfilledPromise](#fulfilledpromise)
* [RejectedPromise](#rejectedpromise)
* [LazyPromise](#lazypromise)
* [Functions](#functions)
* [resolve()](#resolve)
* [reject()](#reject)
* [all()](#all)
* [race()](#race)
* [any()](#any)
* [some()](#some)
* [map()](#map)
* [reduce()](#reduce)
* [PromisorInterface](#promisorinterface)
4. [Examples](#examples)
* [How to use Deferred](#how-to-use-deferred)
* [How promise forwarding works](#how-promise-forwarding-works)
* [Resolution forwarding](#resolution-forwarding)
* [Rejection forwarding](#rejection-forwarding)
* [Mixed resolution and rejection forwarding](#mixed-resolution-and-rejection-forwarding)
* [Progress event forwarding](#progress-event-forwarding)
* [done() vs. then()](#done-vs-then)
5. [Install](#install)
6. [Credits](#credits)
7. [License](#license)
Introduction
------------
Promise is a library implementing
[CommonJS Promises/A](http://wiki.commonjs.org/wiki/Promises/A) for PHP.
It also provides several other useful promise-related concepts, such as joining
multiple promises and mapping and reducing collections of promises.
If you've never heard about promises before,
[read this first](https://gist.github.com/3889970).
Concepts
--------
### Deferred
A **Deferred** represents a computation or unit of work that may not have
completed yet. Typically (but not always), that computation will be something
that executes asynchronously and completes at some point in the future.
### Promise
While a deferred represents the computation itself, a **Promise** represents
the result of that computation. Thus, each deferred has a promise that acts as
a placeholder for its actual result.
API
---
### Deferred
A deferred represents an operation whose resolution is pending. It has separate
promise and resolver parts.
```php
$deferred = new React\Promise\Deferred();
$promise = $deferred->promise();
$deferred->resolve(mixed $value = null);
$deferred->reject(mixed $reason = null);
$deferred->notify(mixed $update = null);
```
The `promise` method returns the promise of the deferred.
The `resolve` and `reject` methods control the state of the deferred.
The deprecated `notify` method is for progress notification.
The constructor of the `Deferred` accepts an optional `$canceller` argument.
See [Promise](#promise-2) for more information.
#### Deferred::promise()
```php
$promise = $deferred->promise();
```
Returns the promise of the deferred, which you can hand out to others while
keeping the authority to modify its state to yourself.
#### Deferred::resolve()
```php
$deferred->resolve(mixed $value = null);
```
Resolves the promise returned by `promise()`. All consumers are notified by
having `$onFulfilled` (which they registered via `$promise->then()`) called with
`$value`.
If `$value` itself is a promise, the promise will transition to the state of
this promise once it is resolved.
#### Deferred::reject()
```php
$deferred->reject(mixed $reason = null);
```
Rejects the promise returned by `promise()`, signalling that the deferred's
computation failed.
All consumers are notified by having `$onRejected` (which they registered via
`$promise->then()`) called with `$reason`.
If `$reason` itself is a promise, the promise will be rejected with the outcome
of this promise regardless whether it fulfills or rejects.
#### Deferred::notify()
> Deprecated in v2.6.0: Progress support is deprecated and should not be used anymore.
```php
$deferred->notify(mixed $update = null);
```
Triggers progress notifications, to indicate to consumers that the computation
is making progress toward its result.
All consumers are notified by having `$onProgress` (which they registered via
`$promise->then()`) called with `$update`.
### PromiseInterface
The promise interface provides the common interface for all promise
implementations.
A promise represents an eventual outcome, which is either fulfillment (success)
and an associated value, or rejection (failure) and an associated reason.
Once in the fulfilled or rejected state, a promise becomes immutable.
Neither its state nor its result (or error) can be modified.
#### Implementations
* [Promise](#promise-2)
* [FulfilledPromise](#fulfilledpromise) (deprecated)
* [RejectedPromise](#rejectedpromise) (deprecated)
* [LazyPromise](#lazypromise) (deprecated)
#### PromiseInterface::then()
```php
$transformedPromise = $promise->then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null);
```
Transforms a promise's value by applying a function to the promise's fulfillment
or rejection value. Returns a new promise for the transformed result.
The `then()` method registers new fulfilled, rejection and progress handlers
with a promise (all parameters are optional):
* `$onFulfilled` will be invoked once the promise is fulfilled and passed
the result as the first argument.
* `$onRejected` will be invoked once the promise is rejected and passed the
reason as the first argument.
* `$onProgress` (deprecated) will be invoked whenever the producer of the promise
triggers progress notifications and passed a single argument (whatever it
wants) to indicate progress.
It returns a new promise that will fulfill with the return value of either
`$onFulfilled` or `$onRejected`, whichever is called, or will reject with
the thrown exception if either throws.
A promise makes the following guarantees about handlers registered in
the same call to `then()`:
1. Only one of `$onFulfilled` or `$onRejected` will be called,
never both.
2. `$onFulfilled` and `$onRejected` will never be called more
than once.
3. `$onProgress` (deprecated) may be called multiple times.
#### See also
* [resolve()](#resolve) - Creating a resolved promise
* [reject()](#reject) - Creating a rejected promise
* [ExtendedPromiseInterface::done()](#extendedpromiseinterfacedone)
* [done() vs. then()](#done-vs-then)
### ExtendedPromiseInterface
The ExtendedPromiseInterface extends the PromiseInterface with useful shortcut
and utility methods which are not part of the Promises/A specification.
#### Implementations
* [Promise](#promise-1)
* [FulfilledPromise](#fulfilledpromise) (deprecated)
* [RejectedPromise](#rejectedpromise) (deprecated)
* [LazyPromise](#lazypromise) (deprecated)
#### ExtendedPromiseInterface::done()
```php
$promise->done(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null);
```
Consumes the promise's ultimate value if the promise fulfills, or handles the
ultimate error.
It will cause a fatal error if either `$onFulfilled` or `$onRejected` th
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
UniSite 不仅仅是一个 CMS UniSite CMS - 这是一个通用系统,您可以使用它启动公告板、服务或商品市场、提供在线汽车租赁的汽车门户、预订和销售房地产的服务等等!该解决方案非常适合发展现有业务或初创企业! 有利可图 在现成的 CMS 上启动项目比自定义开发便宜得多。 快速地 项目启动1天!您节省了最宝贵的东西 - 您的时间,因此也节省了金钱。 只是 我们的系统简单易用,不需要专门的网络开发知识。 现成的赚钱工具 您将获得一个定制的、随时可用且相当易于管理的业务工具。 任何主题的项目 您可以创建自己的类别和过滤器,或者只从我们的列表中选择一个现成的主题,过滤器和类别将使用所有参数自动创建。 一般布告栏 房地产市场 汽车门户网站、备件和配件的销售 特种设备的租售 房车租赁和销售 服务或商品的市场 动物 建设主题 儿童用品 货币化工具 我们明白,每个企业的目标都是利润,因为没有利润,企业就无法运作,因此我们不仅努力为网站用户提供优质服务,而且还考虑可以为您带来利润的功能。 有偿服务。大盘上涨,贵宾住宿,涡轮销售。 安全交易的收益。您将收到每笔交易的一定百分比。 横幅网络
资源推荐
资源详情
资源评论
收起资源包目录
UniSite 内容管理系统
用于发布公告板、市场、租赁和预订服务的现成系统 (2000个子文件)
Client.asciidoc 56KB
IndicesNamespace.asciidoc 49KB
MlNamespace.asciidoc 41KB
CatNamespace.asciidoc 28KB
configuration.asciidoc 16KB
SecurityNamespace.asciidoc 15KB
ClusterNamespace.asciidoc 13KB
per-request-configuration.asciidoc 9KB
futures.asciidoc 8KB
connection-pool.asciidoc 8KB
ClientBuilder.asciidoc 7KB
index-operations.asciidoc 7KB
search-operations.asciidoc 7KB
SnapshotNamespace.asciidoc 7KB
CcrNamespace.asciidoc 6KB
quickstart.asciidoc 6KB
DataFrameTransformDeprecatedNamespace.asciidoc 6KB
crud.asciidoc 6KB
AsyncSearchNamespace.asciidoc 6KB
TransformNamespace.asciidoc 5KB
serializers.asciidoc 5KB
RollupNamespace.asciidoc 5KB
classes.asciidoc 5KB
security.asciidoc 5KB
WatcherNamespace.asciidoc 5KB
php_json_objects.asciidoc 4KB
community.asciidoc 4KB
IlmNamespace.asciidoc 4KB
NodesNamespace.asciidoc 4KB
selectors.asciidoc 4KB
SlmNamespace.asciidoc 4KB
SearchableSnapshotsNamespace.asciidoc 3KB
LicenseNamespace.asciidoc 3KB
installation.asciidoc 3KB
IngestNamespace.asciidoc 3KB
TasksNamespace.asciidoc 3KB
namespaces.asciidoc 2KB
AutoscalingNamespace.asciidoc 2KB
EqlNamespace.asciidoc 2KB
EnrichNamespace.asciidoc 2KB
DanglingIndicesNamespace.asciidoc 2KB
experimental-beta-apis.asciidoc 2KB
8cd00a3aba7c3c158277bc032aac2830.asciidoc 2KB
breaking-changes.asciidoc 2KB
SqlNamespace.asciidoc 1KB
06afce2955f9094d96d27067ebca32e8.asciidoc 1KB
028f6d6ac2594e20b78b8a8f8cbad49d.asciidoc 1KB
XpackNamespace.asciidoc 1KB
MonitoringNamespace.asciidoc 1KB
f29a28fffa7ec604a33a838f48f7ea79.asciidoc 1KB
3cd50a789b8e1f0ebbbc53a8d7ecf656.asciidoc 1KB
dc15e2373e5ecbe09b4ea0858eb63d47.asciidoc 1018B
GraphNamespace.asciidoc 982B
5d9d7b84e2fec7ecd832145cbb951cf1.asciidoc 865B
index.asciidoc 845B
ae9ccfaa146731ab9176df90670db1c2.asciidoc 843B
b5f95bc097a201b29c7200fc8d3d31c1.asciidoc 830B
6bbc613bd4f9aec1bbdbabf5db021d28.asciidoc 784B
e5f50b31f165462d883ecbff45f74985.asciidoc 734B
overview.asciidoc 734B
98b121bf47cebd85671a2cb519688d28.asciidoc 713B
645796e8047967ca4a7635a22a876f4c.asciidoc 687B
1b8655e6ba99fe39933c6eafe78728b7.asciidoc 670B
cd5bc5bf7cd58d7b1492c9c298b345f6.asciidoc 664B
1b8caf0a6741126c6d0ad83b56fce290.asciidoc 662B
34efeade38445b2834749ced59782e25.asciidoc 656B
71b5b2ba9557d0f296ff2de91727d2f6.asciidoc 650B
MigrationNamespace.asciidoc 634B
b0eaf67e5cce24ef8889bf20951ccec1.asciidoc 633B
47bb632c6091ad0cd94bc660bdd309a5.asciidoc 631B
33f148e3d8676de6cc52f58749898a13.asciidoc 631B
804a97ff4d0613e6568e4efb19c52021.asciidoc 617B
7f28f8ae8fcdbd807dadde0b5b007a6d.asciidoc 609B
251ea12c1248385ab409906ac64d9ee9.asciidoc 593B
cfbaea6f0df045c5d940bbb6a9c69cd8.asciidoc 578B
f9636d7ef1a45be4f36418c875cf6bef.asciidoc 566B
7f697eb436dfa3c30dfe610d8c32d132.asciidoc 563B
SslNamespace.asciidoc 556B
36b2778f23d0955255f52c075c4d213d.asciidoc 553B
d8b2a88b5eca99d3691ad3cd40266736.asciidoc 504B
64b9baa6d7556b960b29698f3383aa31.asciidoc 503B
1bc731a4df952228af6dfa6b48627332.asciidoc 496B
4646764bf09911fee7d58630c72d3137.asciidoc 490B
1da77e114459e0b77d78a3dcc8fae429.asciidoc 489B
8871b8fcb6de4f0c7dff22798fb10fb7.asciidoc 481B
179f0a3e84ff4bbac18787a018eabf89.asciidoc 477B
4d56b179242fed59e3d6476f817b6055.asciidoc 477B
a49169b4622918992411fab4ec48191b.asciidoc 477B
973a3ff47fc4ce036ecd9bd363fef9f7.asciidoc 475B
d9474f66970c6955e24b17c7447e7b5f.asciidoc 473B
ad0dcbc7fc619e952c8825b8f307b7b2.asciidoc 472B
6f21a878fee3b43c5332b81aaddbeac7.asciidoc 472B
fa88f6f5a7d728ec4f1d05244228cb09.asciidoc 466B
7b908b1189f076942de8cd497ff1fa59.asciidoc 464B
047266b0d20fdb62ebc72d51952c8f6d.asciidoc 459B
e270f3f721a5712cd11a5ca03554f5b0.asciidoc 458B
5da6efd5b038ada64c9e853c88c1ec47.asciidoc 453B
ac544eb247a29ca42aab13826ca88561.asciidoc 446B
033778305d52746f5ce0a2a922c8e521.asciidoc 438B
5f3a3eefeefe6fa85ec49d499212d245.asciidoc 437B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
2301_77667493
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Pytorch-pytorch深度学习教程之Tensorboard.zip
- 基于C++和Python开发yolov8-face作为人脸检测器dlib作为人脸识别器的人脸考勤系统源码+项目说明.zip
- Pytorch-pytorch深度学习教程之变分自动编码器.zip
- Pytorch-pytorch深度学习教程之神经风格迁移.zip
- Pytorch-pytorch深度学习教程之深度残差网络.zip
- Pytorch-pytorch深度学习教程之循环神经网络.zip
- Pytorch-pytorch深度学习教程之逻辑回归.zip
- Pytorch-pytorch深度学习教程之双向循环网络.zip
- Pytorch-pytorch深度学习教程之卷积神经网络.zip
- Pytorch-pytorch深度学习教程之前馈神经网络.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功