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) (deprecated)
* [LazyPromise](#lazypromise) (deprecated)
#### ExtendedPromiseInterface::done()
```php
$promise->done(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null);
```
Consumes the promise's ult
没有合适的资源?快使用搜索试试~ 我知道了~
ModStartCMS建站系统 Laravel 9.0
共2000个文件
php:8250个
png:576个
js:447个
需积分: 10 0 下载量 143 浏览量
2022-02-22
13:23:30
上传
评论
收藏 33.45MB ZIP 举报
温馨提示
Laravel 9.0 于 2022年2月8日发布,在发布后的第一时间 ModStart 技术团队进行了新技术研究和新框架的适配。ModStart + Laravel 9.0 版于2月11日开始内测。 经过两个星期的内测,目前 3.2.0 正式对外发布。
资源详情
资源评论
资源推荐
收起资源包目录
ModStartCMS建站系统 Laravel 9.0 (2000个子文件)
artisan 2KB
Client.asciidoc 53KB
IndicesNamespace.asciidoc 44KB
MlNamespace.asciidoc 37KB
CatNamespace.asciidoc 26KB
release-notes.asciidoc 15KB
SecurityNamespace.asciidoc 13KB
connecting.asciidoc 12KB
ClusterNamespace.asciidoc 11KB
per-request-configuration.asciidoc 9KB
ClientBuilder.asciidoc 9KB
connection-pool.asciidoc 8KB
futures.asciidoc 8KB
index-operations.asciidoc 7KB
search-operations.asciidoc 7KB
SnapshotNamespace.asciidoc 6KB
crud.asciidoc 6KB
serializers.asciidoc 6KB
AsyncSearchNamespace.asciidoc 6KB
DataFrameTransformDeprecatedNamespace.asciidoc 5KB
classes.asciidoc 5KB
CcrNamespace.asciidoc 5KB
TransformNamespace.asciidoc 5KB
RollupNamespace.asciidoc 5KB
community.asciidoc 4KB
php_json_objects.asciidoc 4KB
selectors.asciidoc 4KB
WatcherNamespace.asciidoc 4KB
host-config.asciidoc 4KB
NodesNamespace.asciidoc 4KB
IlmNamespace.asciidoc 3KB
SearchableSnapshotsNamespace.asciidoc 3KB
installation.asciidoc 3KB
SlmNamespace.asciidoc 3KB
TextStructureNamespace.asciidoc 3KB
LicenseNamespace.asciidoc 3KB
namespaces.asciidoc 2KB
TasksNamespace.asciidoc 2KB
set-retries.asciidoc 2KB
http-meta-data.asciidoc 2KB
IngestNamespace.asciidoc 2KB
helpers.asciidoc 2KB
EqlNamespace.asciidoc 2KB
experimental-beta-apis.asciidoc 2KB
EnrichNamespace.asciidoc 2KB
DanglingIndicesNamespace.asciidoc 2KB
AutoscalingNamespace.asciidoc 2KB
http-handler.asciidoc 2KB
8cd00a3aba7c3c158277bc032aac2830.asciidoc 2KB
breaking-changes.asciidoc 2KB
connection-factory.asciidoc 2KB
logger.asciidoc 1KB
configuration.asciidoc 1KB
LogstashNamespace.asciidoc 1KB
endpoint-closure.asciidoc 1KB
config-hash.asciidoc 1KB
SqlNamespace.asciidoc 1KB
06afce2955f9094d96d27067ebca32e8.asciidoc 1KB
028f6d6ac2594e20b78b8a8f8cbad49d.asciidoc 1KB
MonitoringNamespace.asciidoc 1KB
f29a28fffa7ec604a33a838f48f7ea79.asciidoc 1KB
3cd50a789b8e1f0ebbbc53a8d7ecf656.asciidoc 1KB
XpackNamespace.asciidoc 1KB
dc15e2373e5ecbe09b4ea0858eb63d47.asciidoc 1018B
GraphNamespace.asciidoc 976B
overview.asciidoc 877B
5d9d7b84e2fec7ecd832145cbb951cf1.asciidoc 865B
ae9ccfaa146731ab9176df90670db1c2.asciidoc 843B
b5f95bc097a201b29c7200fc8d3d31c1.asciidoc 830B
6bbc613bd4f9aec1bbdbabf5db021d28.asciidoc 784B
e5f50b31f165462d883ecbff45f74985.asciidoc 734B
98b121bf47cebd85671a2cb519688d28.asciidoc 713B
645796e8047967ca4a7635a22a876f4c.asciidoc 687B
1b8655e6ba99fe39933c6eafe78728b7.asciidoc 670B
cd5bc5bf7cd58d7b1492c9c298b345f6.asciidoc 664B
1b8caf0a6741126c6d0ad83b56fce290.asciidoc 662B
FeaturesNamespace.asciidoc 658B
34efeade38445b2834749ced59782e25.asciidoc 656B
71b5b2ba9557d0f296ff2de91727d2f6.asciidoc 650B
b0eaf67e5cce24ef8889bf20951ccec1.asciidoc 633B
47bb632c6091ad0cd94bc660bdd309a5.asciidoc 631B
33f148e3d8676de6cc52f58749898a13.asciidoc 631B
MigrationNamespace.asciidoc 619B
804a97ff4d0613e6568e4efb19c52021.asciidoc 617B
7f28f8ae8fcdbd807dadde0b5b007a6d.asciidoc 609B
251ea12c1248385ab409906ac64d9ee9.asciidoc 593B
cfbaea6f0df045c5d940bbb6a9c69cd8.asciidoc 578B
f9636d7ef1a45be4f36418c875cf6bef.asciidoc 566B
7f697eb436dfa3c30dfe610d8c32d132.asciidoc 563B
36b2778f23d0955255f52c075c4d213d.asciidoc 553B
SslNamespace.asciidoc 547B
d8b2a88b5eca99d3691ad3cd40266736.asciidoc 504B
64b9baa6d7556b960b29698f3383aa31.asciidoc 503B
1bc731a4df952228af6dfa6b48627332.asciidoc 496B
4646764bf09911fee7d58630c72d3137.asciidoc 490B
1da77e114459e0b77d78a3dcc8fae429.asciidoc 489B
8871b8fcb6de4f0c7dff22798fb10fb7.asciidoc 481B
a49169b4622918992411fab4ec48191b.asciidoc 477B
4d56b179242fed59e3d6476f817b6055.asciidoc 477B
179f0a3e84ff4bbac18787a018eabf89.asciidoc 477B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
ModStartCMS
- 粉丝: 27
- 资源: 51
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于HTML的旅游网页制作源码设计.zip
- 基于HTML的旅游网页制作源码设计.zip
- 大数据实战Demo系统-MaxCompute数据仓库数据转换实践(PDF格式).rar
- 六一儿童节代码祝福六一儿童节代码祝福六一儿童节代码祝福.txt
- sql语句sql语句sql语句sql语句.txt
- ubuntu20.04安装教程ubuntu20.04安装教程.txt
- imgcache.0
- 高分项目基于faster-rcnn知识蒸馏的目标检测模型增量深度学习方法源码.zip
- 基于python和图数据库neo4j构建电影应用(高分毕设项目)
- 基于yolov5+SAHI模块完成超分辨率以及小目标检测演示源码+运行说明.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0