Promise
=======
A lightweight implementation of
[CommonJS Promises/A](http://wiki.commonjs.org/wiki/Promises/A) for PHP.
[![Build Status](https://travis-ci.org/reactphp/promise.svg?branch=master)](http://travis-ci.org/reactphp/promise)
[![Coverage Status](https://coveralls.io/repos/github/reactphp/promise/badge.svg?branch=master)](https://coveralls.io/github/reactphp/promise?branch=master)
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) (deprecate
没有合适的资源?快使用搜索试试~ 我知道了~
PHP实例开发源码-oemshop商城系统.zip
共2000个文件
php:4645个
js:265个
asciidoc:201个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 15 浏览量
2022-11-21
11:08:14
上传
评论
收藏 37.38MB ZIP 举报
温馨提示
PHP实例开发源码—oemshop商城系统.zip PHP实例开发源码—oemshop商城系统.zip PHP实例开发源码—oemshop商城系统.zip
资源推荐
资源详情
资源评论
收起资源包目录
PHP实例开发源码-oemshop商城系统.zip (2000个子文件)
Client.asciidoc 51KB
IndicesNamespace.asciidoc 37KB
CatNamespace.asciidoc 22KB
configuration.asciidoc 17KB
per-request-configuration.asciidoc 10KB
ClusterNamespace.asciidoc 9KB
futures.asciidoc 8KB
connection-pool.asciidoc 8KB
ClientBuilder.asciidoc 7KB
index-operations.asciidoc 7KB
SnapshotNamespace.asciidoc 7KB
search-operations.asciidoc 7KB
quickstart.asciidoc 7KB
crud.asciidoc 6KB
serializers.asciidoc 6KB
security.asciidoc 5KB
php_json_objects.asciidoc 5KB
community.asciidoc 4KB
NodesNamespace.asciidoc 4KB
selectors.asciidoc 4KB
installation.asciidoc 3KB
IngestNamespace.asciidoc 3KB
TasksNamespace.asciidoc 3KB
namespaces.asciidoc 3KB
experimental-beta-apis.asciidoc 2KB
8cd00a3aba7c3c158277bc032aac2830.asciidoc 2KB
breaking-changes.asciidoc 2KB
classes.asciidoc 1KB
028f6d6ac2594e20b78b8a8f8cbad49d.asciidoc 1KB
f29a28fffa7ec604a33a838f48f7ea79.asciidoc 1KB
3cd50a789b8e1f0ebbbc53a8d7ecf656.asciidoc 1KB
dc15e2373e5ecbe09b4ea0858eb63d47.asciidoc 1KB
5d9d7b84e2fec7ecd832145cbb951cf1.asciidoc 898B
index.asciidoc 891B
ae9ccfaa146731ab9176df90670db1c2.asciidoc 888B
b5f95bc097a201b29c7200fc8d3d31c1.asciidoc 871B
6bbc613bd4f9aec1bbdbabf5db021d28.asciidoc 815B
e5f50b31f165462d883ecbff45f74985.asciidoc 766B
overview.asciidoc 749B
98b121bf47cebd85671a2cb519688d28.asciidoc 743B
645796e8047967ca4a7635a22a876f4c.asciidoc 716B
1b8655e6ba99fe39933c6eafe78728b7.asciidoc 705B
1b8caf0a6741126c6d0ad83b56fce290.asciidoc 693B
cd5bc5bf7cd58d7b1492c9c298b345f6.asciidoc 691B
34efeade38445b2834749ced59782e25.asciidoc 683B
71b5b2ba9557d0f296ff2de91727d2f6.asciidoc 677B
47bb632c6091ad0cd94bc660bdd309a5.asciidoc 660B
b0eaf67e5cce24ef8889bf20951ccec1.asciidoc 660B
33f148e3d8676de6cc52f58749898a13.asciidoc 657B
804a97ff4d0613e6568e4efb19c52021.asciidoc 646B
7f28f8ae8fcdbd807dadde0b5b007a6d.asciidoc 635B
251ea12c1248385ab409906ac64d9ee9.asciidoc 620B
cfbaea6f0df045c5d940bbb6a9c69cd8.asciidoc 604B
f9636d7ef1a45be4f36418c875cf6bef.asciidoc 591B
7f697eb436dfa3c30dfe610d8c32d132.asciidoc 589B
36b2778f23d0955255f52c075c4d213d.asciidoc 579B
64b9baa6d7556b960b29698f3383aa31.asciidoc 528B
d8b2a88b5eca99d3691ad3cd40266736.asciidoc 528B
1bc731a4df952228af6dfa6b48627332.asciidoc 520B
1da77e114459e0b77d78a3dcc8fae429.asciidoc 513B
4646764bf09911fee7d58630c72d3137.asciidoc 512B
8871b8fcb6de4f0c7dff22798fb10fb7.asciidoc 502B
4d56b179242fed59e3d6476f817b6055.asciidoc 500B
179f0a3e84ff4bbac18787a018eabf89.asciidoc 499B
a49169b4622918992411fab4ec48191b.asciidoc 498B
d9474f66970c6955e24b17c7447e7b5f.asciidoc 495B
973a3ff47fc4ce036ecd9bd363fef9f7.asciidoc 495B
ad0dcbc7fc619e952c8825b8f307b7b2.asciidoc 494B
6f21a878fee3b43c5332b81aaddbeac7.asciidoc 493B
fa88f6f5a7d728ec4f1d05244228cb09.asciidoc 489B
7b908b1189f076942de8cd497ff1fa59.asciidoc 485B
047266b0d20fdb62ebc72d51952c8f6d.asciidoc 480B
e270f3f721a5712cd11a5ca03554f5b0.asciidoc 479B
5da6efd5b038ada64c9e853c88c1ec47.asciidoc 474B
ac544eb247a29ca42aab13826ca88561.asciidoc 465B
5f3a3eefeefe6fa85ec49d499212d245.asciidoc 458B
033778305d52746f5ce0a2a922c8e521.asciidoc 458B
98aeb275f829b5f7b8eb2147701565ff.asciidoc 451B
fdd38f0d248385a444c777e7acd97846.asciidoc 450B
be1bd47393646ac6bbee177d1cdb7738.asciidoc 444B
a2a25aad1fea9a541b52ac613c78fb64.asciidoc 443B
78c96113ae4ed0054e581b17542528a7.asciidoc 442B
0e118857b815b62118a30c042f079db1.asciidoc 441B
68721288dc9ad8aa1b55099b4d303051.asciidoc 439B
6a4679531e64c492fce16dc12de6dcb0.asciidoc 434B
93f1bdd72e79827dcf9a34efa02fd977.asciidoc 432B
dfef545b1e2c247bafd1347e8e807ac1.asciidoc 432B
35e8da9410b8432cf4095f2541ad7b1d.asciidoc 428B
0bbd30b9be3e54ff3028b9f4459634d2.asciidoc 425B
0afaf1cad692e6201aa574c8feb6e622.asciidoc 422B
9a4d5e41c52c20635d1fd9c6e13f6c7a.asciidoc 419B
764f9884b370cbdc82a1c5c42ed40ff3.asciidoc 415B
5c2f486c27bd5346e512265f93375d16.asciidoc 415B
60ee33f3acfdd0fe6f288ac77312c780.asciidoc 412B
58b5003c0a53a39bf509aa3797aad471.asciidoc 408B
1f6fe6833686e38c3711c6f2aa00a078.asciidoc 407B
4b90feb9d5d3dbfce424dac0341320b7.asciidoc 401B
e30ea6e3823a139d7693d8cce1920a06.asciidoc 399B
53b908c3432118c5a6e460f74d32006b.asciidoc 397B
f2d68493abd3ca430bd03a7f7f8d18f9.asciidoc 396B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
毕业_设计
- 粉丝: 1944
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- yolo开发教程&案例&相关项目举例概要知识点总结.docx
- java期末大作业学生成绩管理系统源码+数据库+报告文档(95分以上)
- 1996-2023年各省农林牧渔总产值及农业、林业、牧业、渔业总产值数据(无缺失).xlsx
- vue开发教程&案例&相关项目举例说明概要知识点总结.docx
- ExtJs使用示例代码之窗口组件和异步请求
- 18508319_5640_FlowerShop.zip
- 网络安全相关的密码学、网络攻防、安全分析等项目举例与概要.docx
- java期末大作业课程设计学生成绩管理系统源码+数据库+报告(高分项目)
- maven下载、安装、配置与使用教程概要说明与总结.docx
- kubebuilder v4.0.0
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功