Class: Promise

Promise

new Promise()

engineExtensions/util/when.js, line 126

Trusted Promise constructor. A Promise created from this constructor is a trusted when.js promise. Any other duck-typed promise is considered untrusted.

Methods

always(onFulfilledOrRejected, onProgress){Promise}

engineExtensions/util/when.js, line 146

Register a callback that will be called when a promise is fulfilled or rejected. Optionally also register a progress handler. Shortcut for .then(onFulfilledOrRejected, onFulfilledOrRejected, onProgress)

Name Type Description
onFulfilledOrRejected function 可选 nullable
onProgress function 可选 nullable
Returns:
Type Description
Promise

otherwise(onRejected){Promise}

engineExtensions/util/when.js, line 155

Register a rejection handler. Shortcut for .then(undefined, onRejected)

Name Type Description
onRejected function nullable
Returns:
Type Description
Promise

spread(onFulfilled){Promise}

engineExtensions/util/when.js, line 180

Assumes that this promise will fulfill with an array, and arranges for the onFulfilled to be called with the array as its argument list i.e. onFulfilled.spread(undefined, array).

Name Type Description
onFulfilled function

function to receive spread arguments

Returns:
Type Description
Promise

yield(value){Promise}

engineExtensions/util/when.js, line 167

Shortcut for .then(function() { return value; })

Name Type Description
value *
Returns:
Type Description
Promise a promise that:
  • is fulfilled if value is not a promise, or
  • if value is a promise, will fulfill with its value, or reject with its reason.