ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
|
An implementation of the Promise pattern. More...
Data Structures | |
class | FunctionsTest |
class | PromiseTest |
Public Member Functions | |
__construct (callable $executor=null) | |
Creates the promise. More... | |
then (callable $onFulfilled=null, callable $onRejected=null) | |
This method allows you to specify the callback that will be called after the promise has been fulfilled or rejected. More... | |
otherwise (callable $onRejected) | |
Add a callback for when this promise is rejected. More... | |
fulfill ($value=null) | |
Marks this promise as fulfilled and sets its return value. More... | |
reject ($reason=null) | |
Marks this promise as rejected, and set it's rejection reason. More... | |
wait () | |
Stops execution until this promise is resolved. More... | |
error (callable $onRejected) | |
Alias for 'otherwise'. More... | |
Static Public Member Functions | |
static | all (array $promises) |
Deprecated. More... | |
Data Fields | |
const | PENDING = 0 |
The asynchronous operation is pending. More... | |
const | FULFILLED = 1 |
The asynchronous operation has completed, and has a result. More... | |
const | REJECTED = 2 |
The asynchronous operation has completed with an error. More... | |
$state = self::PENDING | |
Protected Attributes | |
$subscribers = [] | |
$value = null | |
Private Member Functions | |
invokeCallback (Promise $subPromise, callable $callBack=null) | |
This method is used to call either an onFulfilled or onRejected callback. More... | |
An implementation of the Promise pattern.
A promise represents the result of an asynchronous operation. At any given point a promise can be in one of three states:
To get a callback when the operation has finished, use the then
method.
Definition at line 23 of file Promise.php.
Sabre\Event\Promise::__construct | ( | callable | $executor = null | ) |
Creates the promise.
The passed argument is the executor. The executor is automatically called with two arguments.
Each are callbacks that map to $this->fulfill and $this->reject. Using the executor is optional.
callable | $executor |
Definition at line 58 of file Promise.php.
|
static |
Deprecated.
Promise[] | $promises |
Definition at line 314 of file Promise.php.
Referenced by Sabre\Event\Promise\FunctionsTest\testAll(), Sabre\Event\PromiseTest\testAll(), Sabre\Event\Promise\PromiseTest\testAll(), Sabre\Event\Promise\FunctionsTest\testAllReject(), Sabre\Event\PromiseTest\testAllReject(), Sabre\Event\Promise\PromiseTest\testAllReject(), Sabre\Event\Promise\FunctionsTest\testAllRejectThenResolve(), Sabre\Event\PromiseTest\testAllRejectThenResolve(), and Sabre\Event\Promise\PromiseTest\testAllRejectThenResolve().
Sabre\Event\Promise::error | ( | callable | $onRejected | ) |
Alias for 'otherwise'.
This function is now deprecated and will be removed in a future version.
callable | $onRejected |
Definition at line 299 of file Promise.php.
References Sabre\Event\Promise\otherwise().
Referenced by Sabre\Event\Promise\all().
Sabre\Event\Promise::fulfill | ( | $value = null | ) |
Marks this promise as fulfilled and sets its return value.
mixed | $value |
Definition at line 141 of file Promise.php.
References Sabre\Event\Promise\$value, and Sabre\Event\Promise\invokeCallback().
Referenced by Sabre\Event\Promise\invokeCallback().
|
private |
This method is used to call either an onFulfilled or onRejected callback.
This method makes sure that the result of these callbacks are handled correctly, and any chained promises are also correctly fulfilled or rejected.
Promise | $subPromise | |
callable | $callBack |
Definition at line 252 of file Promise.php.
References $result, Sabre\Event\Promise\fulfill(), Sabre\Event\Loop\nextTick(), and Sabre\Event\Promise\reject().
Referenced by Sabre\Event\Promise\fulfill(), Sabre\Event\Promise\reject(), and Sabre\Event\Promise\then().
Sabre\Event\Promise::otherwise | ( | callable | $onRejected | ) |
Add a callback for when this promise is rejected.
Its usage is identical to then(). However, the otherwise() function is preferred.
callable | $onRejected |
Definition at line 129 of file Promise.php.
References Sabre\Event\Promise\then().
Referenced by Sabre\Event\Promise\error().
Sabre\Event\Promise::reject | ( | $reason = null | ) |
Marks this promise as rejected, and set it's rejection reason.
While it's possible to use any PHP value as the reason, it's highly recommended to use an Exception for this.
mixed | $reason |
Definition at line 161 of file Promise.php.
References Sabre\Event\Promise\invokeCallback().
Referenced by Sabre\Event\Promise\invokeCallback(), and Sabre\Event\Promise\FunctionsTest\testReject().
Sabre\Event\Promise::then | ( | callable | $onFulfilled = null , |
callable | $onRejected = null |
||
) |
This method allows you to specify the callback that will be called after the promise has been fulfilled or rejected.
Both arguments are optional.
This method returns a new promise, which can be used for chaining. If either the onFulfilled or onRejected callback is called, you may return a result from this callback.
If the result of this callback is yet another promise, the result of that promise will be used to set the result of the returned promise.
If either of the callbacks return any other value, the returned promise is automatically fulfilled with that value.
If either of the callbacks throw an exception, the returned promise will be rejected and the exception will be passed back.
callable | $onFulfilled | |
callable | $onRejected |
Definition at line 92 of file Promise.php.
References Sabre\Event\Promise\invokeCallback().
Referenced by Sabre\Event\Promise\otherwise(), Sabre\Event\Promise\PromiseTest\testChain(), Sabre\Event\Promise\PromiseTest\testChainPromise(), and Sabre\Event\Promise\PromiseTest\testFromFailureHandler().
Sabre\Event\Promise::wait | ( | ) |
Stops execution until this promise is resolved.
This method stops exection completely. If the promise is successful with a value, this method will return this value. If the promise was rejected, this method will throw an exception.
This effectively turns the asynchronous operation into a synchronous one. In PHP it might be useful to call this on the last promise in a chain.
Exception |
Definition at line 187 of file Promise.php.
References $type, Sabre\Event\Promise\$value, and Sabre\Event\Loop\tick().
Sabre\Event\Promise::$state = self::PENDING |
Definition at line 45 of file Promise.php.
|
protected |
Definition at line 229 of file Promise.php.
|
protected |
Definition at line 239 of file Promise.php.
Referenced by Sabre\Event\Promise\fulfill(), Sabre\Event\Promise\resolve(), Sabre\Event\Promise\FunctionsTest\testAll(), Sabre\Event\Promise\PromiseTest\testAll(), Sabre\Event\Promise\FunctionsTest\testAllReject(), Sabre\Event\Promise\PromiseTest\testAllReject(), Sabre\Event\Promise\FunctionsTest\testAllRejectThenResolve(), Sabre\Event\Promise\PromiseTest\testAllRejectThenResolve(), Sabre\Event\Promise\PromiseTest\testChain(), Sabre\Event\Promise\PromiseTest\testChainPromise(), Sabre\Event\Promise\PromiseTest\testFail(), Sabre\Event\Promise\PromiseTest\testPendingFail(), Sabre\Event\Promise\PromiseTest\testPendingResult(), Sabre\Event\Promise\FunctionsTest\testRace(), Sabre\Event\Promise\FunctionsTest\testRaceReject(), Sabre\Event\Promise\FunctionsTest\testReject(), Sabre\Event\Promise\FunctionsTest\testResolve(), Sabre\Event\Promise\PromiseTest\testSuccess(), and Sabre\Event\Promise\wait().
const Sabre\Event\Promise::FULFILLED = 1 |
The asynchronous operation has completed, and has a result.
Definition at line 33 of file Promise.php.
const Sabre\Event\Promise::PENDING = 0 |
The asynchronous operation is pending.
Definition at line 28 of file Promise.php.
Referenced by Sabre\Event\coroutine().
const Sabre\Event\Promise::REJECTED = 2 |
The asynchronous operation has completed with an error.
Definition at line 38 of file Promise.php.