Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

(no description)

File Size: 97 lines (3 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

PromiseInterface:: (7 methods):
  then()
  otherwise()
  getState()
  resolve()
  reject()
  cancel()
  wait()


Interface: PromiseInterface  - X-Ref

A promise represents the eventual result of an asynchronous operation.

The primary way of interacting with a promise is through its then method,
which registers callbacks to receive either a promise’s eventual value or
the reason why the promise cannot be fulfilled.

then(callable $onFulfilled = null,callable $onRejected = null)   X-Ref
Appends fulfillment and rejection handlers to the promise, and returns
a new promise resolving to the return value of the called handler.

param: callable $onFulfilled Invoked when the promise fulfills.
param: callable $onRejected  Invoked when the promise is rejected.
return: PromiseInterface

otherwise(callable $onRejected)   X-Ref
Appends a rejection handler callback to the promise, and returns a new
promise resolving to the return value of the callback if it is called,
or to its original fulfillment value if the promise is instead
fulfilled.

param: callable $onRejected Invoked when the promise is rejected.
return: PromiseInterface

getState()   X-Ref
Get the state of the promise ("pending", "rejected", or "fulfilled").

The three states can be checked against the constants defined on
PromiseInterface: PENDING, FULFILLED, and REJECTED.

return: string

resolve($value)   X-Ref
Resolve the promise with the given value.

param: mixed $value

reject($reason)   X-Ref
Reject the promise with the given reason.

param: mixed $reason

cancel()   X-Ref
Cancels the promise if possible.


wait($unwrap = true)   X-Ref
Waits until the promise completes if possible.

Pass $unwrap as true to unwrap the result of the promise, either
returning the resolved value or throwing the rejected exception.

If the promise cannot be waited on, then the promise will be rejected.

param: bool $unwrap
return: mixed