promise.js
No description.

File Location

/goog/promise/promise.js

Classes

goog.Promise
Promises provide a result that may be resolved asynchronously. A Promise may be resolved by being fulfilled or rejected with a value, which will be known as the fulfillment value or the rejection reason. Whether fulfilled or rejected, the Promise result is immutable once it is set. Promises may represent results of any type, including undefined. Rejection reasons are typically Errors, but may also be of any type. Closure Promises allow for optional type annotations that enforce that fulfillment values are of the appropriate types at compile time. The result of a Promise is accessible by calling then and registering onFulfilled and onRejected callbacks. Once the Promise resolves, the relevant callbacks are invoked with the fulfillment value or rejection reason as argument. Callbacks are always invoked in the order they were registered, even when additional then calls are made from inside another callback. A callback is always run asynchronously sometime after the scope containing the registering then invocation has returned. If a Promise is resolved with another Promise, the first Promise will block until the second is resolved, and then assumes the same result as the second Promise. This allows Promises to depend on the results of other Promises, linking together multiple asynchronous operations. This implementation is compatible with the Promises/A+ specification and passes that specification's conformance test suite. A Closure Promise may be resolved with a Promise instance (or sufficiently compatible Promise-like object) created by other Promise implementations. From the specification, Promise-like objects are known as "Thenables".
goog.Promise.CancellationError
Error used as a rejection reason for canceled Promises.
goog.Promise.Resolver_
Internal implementation of the resolver interface.

Public Protected Private

Enumerations

Global Functions

goog.Promise.addUnhandledRejection_(promisereason)
Marks this rejected Promise as unhandled. If no onRejected callback is called for this Promise before the UNHANDLED_REJECTION_DELAY expires, the reason will be passed to the unhandled rejection handler. The handler typically rethrows the rejection reason so that it becomes visible in the developer console.
Arguments:
promise : !goog.Promise
The rejected Promise.
reason : *
The Promise rejection reason.
code »
goog.Promise.all(promises) !goog.Promise.<!Array.<TYPE>>
No description.
Arguments:
promises : !Array.<!(goog.Thenable.<TYPE> | Thenable)>
No description.
Returns: !goog.Promise.<!Array.<TYPE>>  A Promise that receives a list of every fulfilled value once every input Promise (or Promise-like) is successfully fulfilled, or is rejected by the first rejection result.
code »
goog.Promise.firstFulfilled(promises) !goog.Promise.<TYPE>
No description.
Arguments:
promises : !Array.<!(goog.Thenable.<TYPE> | Thenable)>
No description.
Returns: !goog.Promise.<TYPE>  A Promise that receives the value of the first input to be fulfilled, or is rejected with a list of every rejection reason if all inputs are rejected.
code »
goog.Promise.handleRejection_()
A method that is invoked with the rejection reasons for Promises that are rejected but have no onRejected callbacks registered yet.
code »
goog.Promise.all&function%0&onFulfill()
No description.
code »
goog.Promise.firstFulfilled&function%0&onFulfill()
No description.
code »
goog.Promise.all&function%0&onReject()
No description.
code »
goog.Promise.firstFulfilled&function%0&onReject()
No description.
code »
goog.Promise.race(promises) !goog.Promise.<TYPE>
No description.
Arguments:
promises : !Array.<!(goog.Thenable.<TYPE> | Thenable)>
No description.
Returns: !goog.Promise.<TYPE>  A Promise that receives the result of the first Promise (or Promise-like) input to complete.
code »
goog.Promise.reject(opt_reason) !goog.Promise
No description.
Arguments:
opt_reason : *=
No description.
Returns: !goog.Promise  A new Promise that is immediately rejected with the given reason.
code »
goog.Promise.withResolver&reject()
No description.
code »
goog.Promise.resolve(opt_value) !goog.Promise.<TYPE>
No description.
Arguments:
opt_value : (TYPE | goog.Thenable.<TYPE> | Thenable)=
No description.
Returns: !goog.Promise.<TYPE>  A new Promise that is immediately resolved with the given value.
code »
goog.Promise.withResolver&resolve()
No description.
code »
goog.Promise.setUnhandledRejectionHandler(handler)
Sets a handler that will be called with reasons from unhandled rejected Promises. If the rejected Promise (or one of its descendants) has an onRejected callback registered, the rejection will be considered handled, and the rejection handler will not be called. By default, unhandled rejections are rethrown so that the error may be captured by the developer console or a window.onerror handler.
Arguments:
handler : function(*)
A function that will be called with reasons from rejected Promises. Defaults to goog.async.throwException.
code »
goog.Promise.withResolver() !goog.promise.Resolver.<TYPE>
No description.
Returns: !goog.promise.Resolver.<TYPE>  Resolver wrapping the promise and its resolve / reject functions. Resolving or rejecting the resolver resolves or rejects the promise.
code »

Directory promise

File Reference