Promise
in package
implements
PromiseInterface
Tags
Table of Contents
Interfaces
Properties
- $cancelled : bool
- $canceller : callable(callable(T): void, callable(Throwable): void): void|null
- $handlers : array<int, callable(PromiseInterface<string|int, T>): void>
- $requiredCancelRequests : int
- $result : PromiseInterface<string|int, T>|null
Methods
- __construct() : mixed
- always() : PromiseInterface<string|int, T>
- [Deprecated] Allows you to execute "cleanup" type tasks in a promise chain.
- cancel() : void
- The `cancel()` method notifies the creator of the promise that there is no further interest in the results of the operation.
- catch() : PromiseInterface<string|int, T|TRejected>
- Registers a rejection handler for promise. It is a shortcut for:
- finally() : PromiseInterface<string|int, T>
- Allows you to execute "cleanup" type tasks in a promise chain.
- otherwise() : PromiseInterface<string|int, T|TRejected>
- [Deprecated] Registers a rejection handler for a promise.
- then() : PromiseInterface<string|int, mixed>
- 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.
- call() : void
- reject() : void
- resolver() : callable
- settle() : void
- unwrap() : PromiseInterface<string|int, T>
Properties
$cancelled
private
bool
$cancelled
= false
$canceller
private
callable(callable(T): void, callable(Throwable): void): void|null
$canceller
$handlers
private
array<int, callable(PromiseInterface<string|int, T>): void>
$handlers
= []
$requiredCancelRequests
private
int
$requiredCancelRequests
= 0
$result
private
PromiseInterface<string|int, T>|null
$result
Methods
__construct()
public
__construct(callable(callable(T): void, callable(Throwable): void): void $resolver[, callable(callable(T): void, callable(Throwable): void): void|null $canceller = null ]) : mixed
Parameters
- $resolver : callable(callable(T): void, callable(Throwable): void): void
- $canceller : callable(callable(T): void, callable(Throwable): void): void|null = null
always()
[Deprecated] Allows you to execute "cleanup" type tasks in a promise chain.
public
always(callable $onFulfilledOrRejected) : PromiseInterface<string|int, T>
Parameters
- $onFulfilledOrRejected : callable
Tags
Return values
PromiseInterface<string|int, T>cancel()
The `cancel()` method notifies the creator of the promise that there is no further interest in the results of the operation.
public
cancel() : void
Once a promise is settled (either fulfilled or rejected), calling cancel()
on
a promise has no effect.
catch()
Registers a rejection handler for promise. It is a shortcut for:
public
catch(
Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 78
callable(TThrowable): Array $onRejected) : PromiseInterface<string|int, T|TRejected>
Parameters
- $onRejected : Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 78 callable(TThrowable): Array
Tags
Return values
PromiseInterface<string|int, T|TRejected>finally()
Allows you to execute "cleanup" type tasks in a promise chain.
public
finally(callable $onFulfilledOrRejected) : PromiseInterface<string|int, T>
It arranges for $onFulfilledOrRejected
to be called, with no arguments,
when the promise is either fulfilled or rejected.
- If
$promise
fulfills, and$onFulfilledOrRejected
returns successfully,$newPromise
will fulfill with the same value as$promise
. - If
$promise
fulfills, and$onFulfilledOrRejected
throws or returns a rejected promise,$newPromise
will reject with the thrown exception or rejected promise's reason. - If
$promise
rejects, and$onFulfilledOrRejected
returns successfully,$newPromise
will reject with the same reason as$promise
. - If
$promise
rejects, and$onFulfilledOrRejected
throws or returns a rejected promise,$newPromise
will reject with the thrown exception or rejected promise's reason.
finally()
behaves similarly to the synchronous finally statement. When combined
with catch()
, finally()
allows you to write code that is similar to the familiar
synchronous catch/finally pair.
Consider the following synchronous code:
try {
return doSomething();
} catch(\Exception $e) {
return handleError($e);
} finally {
cleanup();
}
Similar asynchronous code (with doSomething()
that returns a promise) can be
written:
return doSomething()
->catch('handleError')
->finally('cleanup');
Parameters
- $onFulfilledOrRejected : callable
Return values
PromiseInterface<string|int, T>otherwise()
[Deprecated] Registers a rejection handler for a promise.
public
otherwise(callable $onRejected) : PromiseInterface<string|int, T|TRejected>
Parameters
- $onRejected : callable
Tags
Return values
PromiseInterface<string|int, T|TRejected>then()
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.
public
then([callable|null $onFulfilled = null ][, callable|null $onRejected = null ]) : PromiseInterface<string|int, mixed>
The then()
method registers new fulfilled and rejection 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.
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()
:
- Only one of
$onFulfilled
or$onRejected
will be called, never both. -
$onFulfilled
and$onRejected
will never be called more than once.
Parameters
- $onFulfilled : callable|null = null
- $onRejected : callable|null = null
Return values
PromiseInterface<string|int, mixed>call()
private
call(callable(callable(mixed): void, callable(Throwable): void): void $cb) : void
Parameters
- $cb : callable(callable(mixed): void, callable(Throwable): void): void
reject()
private
reject(Throwable $reason) : void
Parameters
- $reason : Throwable
resolver()
private
resolver([callable|null $onFulfilled = null ][, callable|null $onRejected = null ]) : callable
Parameters
- $onFulfilled : callable|null = null
- $onRejected : callable|null = null
Return values
callablesettle()
private
settle(PromiseInterface<string|int, T> $result) : void
Parameters
- $result : PromiseInterface<string|int, T>
unwrap()
private
unwrap(PromiseInterface<string|int, T> $promise) : PromiseInterface<string|int, T>
Parameters
- $promise : PromiseInterface<string|int, T>