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)
* [RejectedPromise](#rejectedpromise)
* [LazyPromise](#lazypromise)
#### 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)
* [RejectedPromise](#rejectedpromise)
* [LazyPromise](#lazypromise)
#### 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 c
没有合适的资源?快使用搜索试试~ 我知道了~
在线客服系统运营版2021,多商户机器人,自助注册客服系统源码,im即时通讯聊天
共2000个文件
php:813个
gif:274个
js:241个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 23 浏览量
2022-03-21
13:01:17
上传
评论
收藏 99.54MB ZIP 举报
温馨提示
-加强客户体验,商机转化率提升50%-提升在线客服效率,专注线上转化多重技术保障-动态DNS持续重连直至到达-全面的SLA保障体系,大数据集群部署多渠道接入-AI智能客服支持桌面网站、移动网站、App、微信、微博、短信等多种渠道接入-客服可以在一个后端接待所有渠道来访的客户多种接待方式-企业可根据自身的业务场景来决定采用人工客服还是机器人客服的方式进行接待-也可以配置为人工客服优先接待或者智能机器人客服优先接待智能路由分配,开启高效服务-多种分配规则,空闲率分配,随机分配,熟客优先,灵活选择-指定客服、技能组分配,提供最合适的服务-咨询量大时,支持排队溢出,服务下沉,让用户不再等待智能客服机器人,7*24小时不间断服务-一键开通,全天候服务用户,告别排队-人机协作模式辅助人工客服,高效接待-覆盖率、精确率等各项指标均领行行业全方位用户画像-对接thinkphp系统,结合分组体系,精准描绘用户画像,完成用户分层-地区/会话发起页/来源等用户轨迹完整记录,主动营销有据可依-全渠道历史服务记录统一查看,用户需求全面掌握
资源推荐
资源详情
资源评论
收起资源包目录
在线客服系统运营版2021,多商户机器人,自助注册客服系统源码,im即时通讯聊天 (2000个子文件)
Client.asciidoc 50KB
IndicesNamespace.asciidoc 36KB
CatNamespace.asciidoc 21KB
configuration.asciidoc 16KB
per-request-configuration.asciidoc 9KB
ClusterNamespace.asciidoc 8KB
futures.asciidoc 8KB
connection-pool.asciidoc 8KB
index-operations.asciidoc 7KB
search-operations.asciidoc 7KB
SnapshotNamespace.asciidoc 7KB
ClientBuilder.asciidoc 7KB
quickstart.asciidoc 6KB
crud.asciidoc 6KB
serializers.asciidoc 5KB
security.asciidoc 5KB
php_json_objects.asciidoc 4KB
community.asciidoc 4KB
NodesNamespace.asciidoc 4KB
selectors.asciidoc 4KB
installation.asciidoc 4KB
IngestNamespace.asciidoc 3KB
namespaces.asciidoc 3KB
TasksNamespace.asciidoc 2KB
experimental-beta-apis.asciidoc 2KB
classes.asciidoc 1KB
06afce2955f9094d96d27067ebca32e8.asciidoc 1KB
028f6d6ac2594e20b78b8a8f8cbad49d.asciidoc 1KB
breaking-changes.asciidoc 1KB
f29a28fffa7ec604a33a838f48f7ea79.asciidoc 1KB
dc15e2373e5ecbe09b4ea0858eb63d47.asciidoc 1KB
5d9d7b84e2fec7ecd832145cbb951cf1.asciidoc 892B
98b121bf47cebd85671a2cb519688d28.asciidoc 740B
overview.asciidoc 736B
index.asciidoc 725B
cd5bc5bf7cd58d7b1492c9c298b345f6.asciidoc 691B
34efeade38445b2834749ced59782e25.asciidoc 683B
71b5b2ba9557d0f296ff2de91727d2f6.asciidoc 677B
804a97ff4d0613e6568e4efb19c52021.asciidoc 644B
7f28f8ae8fcdbd807dadde0b5b007a6d.asciidoc 636B
4646764bf09911fee7d58630c72d3137.asciidoc 517B
a49169b4622918992411fab4ec48191b.asciidoc 504B
4d56b179242fed59e3d6476f817b6055.asciidoc 504B
fa88f6f5a7d728ec4f1d05244228cb09.asciidoc 493B
033778305d52746f5ce0a2a922c8e521.asciidoc 465B
6a4679531e64c492fce16dc12de6dcb0.asciidoc 441B
93f1bdd72e79827dcf9a34efa02fd977.asciidoc 439B
dfef545b1e2c247bafd1347e8e807ac1.asciidoc 438B
35e8da9410b8432cf4095f2541ad7b1d.asciidoc 436B
0ac9916f47a2483b89c1416684af322a.asciidoc 431B
0afaf1cad692e6201aa574c8feb6e622.asciidoc 430B
92185a88554737bfa27b6bef09590c61.asciidoc 423B
7f56755fb6c42f7e6203339a6d0cb6e6.asciidoc 398B
162b5b693b713f0bfab1209d59443c46.asciidoc 396B
774d715155cd13713e6e327adf6ce328.asciidoc 386B
f70a54cd9a9f4811bf962e469f2ca2ea.asciidoc 385B
97bcd92ef148312d41e69f0d18284327.asciidoc 383B
527324766814561b75aaee853ede49a7.asciidoc 382B
5043b83a89091fa00edb341ddf7ba370.asciidoc 381B
f085fb032dae56a3b104ab874eaea2ad.asciidoc 379B
d50a3835bf5795ac73e58906a3413544.asciidoc 379B
6138d6919f3cbaaf61e1092f817d295c.asciidoc 378B
4466d410e06712c63328de4db249e6da.asciidoc 368B
e5d2172b524332196cac0f031c043659.asciidoc 360B
9a8995fd31351045d99c78e40444c8ea.asciidoc 341B
e0d6e02b998bdea99c9c08dcc3630c5e.asciidoc 336B
048d8abd42d094bbdcf4452a58ccb35b.asciidoc 322B
bb143628fd04070683eeeadc9406d9cc.asciidoc 321B
d718b63cf1b6591a1d59a0cf4fd995eb.asciidoc 321B
b918d6b798da673a33e49b94f61dcdc0.asciidoc 321B
b9c5d7ca6ca9c6f747201f45337a4abf.asciidoc 312B
36818c6d9f434d387819c30bd9addb14.asciidoc 304B
625dc94df1f9affb49a082fd99d41620.asciidoc 304B
4d46dbb96125b27f46299547de9d8709.asciidoc 291B
fa2fe60f570bd930d2891778c6efbfe6.asciidoc 285B
namespaces.asciidoc 281B
1f336ecc62480c1d56351cc2f82d0d08.asciidoc 277B
php-version-requirement.asciidoc 209B
1c23507edd7a3c18538b68223378e4ab.asciidoc 178B
fabe14480624a99e8ee42c7338672058.asciidoc 176B
interfaces.asciidoc 147B
elasticsearch-service.bat 7KB
elasticsearch-env.bat 2KB
elasticsearch.bat 2KB
elasticsearch-cli.bat 867B
elasticsearch-plugin.bat 309B
elasticsearch-translog.bat 256B
elasticsearch-keystore.bat 253B
elasticsearch-shard.bat 250B
start_for_win.bat 119B
_0.cfe 405B
_0.cfe 405B
_0.cfe 405B
_1.cfe 405B
_0.cfs 3KB
_1.cfs 2KB
_0.cfs 2KB
_0.cfs 2KB
translog.ckp 88B
translog.ckp 88B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
- 堂上燕源码2023-01-09资源很受用,资源主总结的很全面,内容与描述一致,解决了我当下的问题。
办公模板库素材蛙
- 粉丝: 1560
- 资源: 2289
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功