The goog.async.DeferredList Class

goog.async.DeferredList
> goog.async.Deferred

goog.async.DeferredList(list, opt_fireOnOneCallback, opt_fireOnOneErrback, opt_consumeErrors, opt_canceller, opt_defaultScope)

Constructs an object that waits on the results of multiple asynchronous operations and marshals the results. It is itself a Deferred, and sends results to its registered callback chain. Each instance is single use and may only fire once. Unless overridden by one of the options below, the DeferredList will wait for a result from every input Deferred. The results are stored in a list of two-element arrays as [success, result], where success is whether that result was from a callback or errback. Once all results are available, the DeferredList's callback chain is invoked with the full result list.

list {!Array.<!goog.async.Deferred>}
An array of deferred objects to wait for.
opt_fireOnOneCallback {boolean=}
Whether to stop waiting as soon as one input completes successfully. In this case, the DeferredList's callback chain will be called with a two element array, [index, result], where index identifies which input Deferred produced the result.
opt_fireOnOneErrback {boolean=}
Whether to stop waiting as soon as one input reports an error. The error result is passed to the DeferredList's error callback chain.
opt_consumeErrors {boolean=}
When true, will stop propagation of the error callback chain for input deferred objects. If the failing deferred has a registered callback after this DeferredList, it will be called with null instead of an Error.
opt_canceller {Function=}
A function that will be called if the deferred list is canceled.
opt_defaultScope {Object=}
The default scope to call callbacks with.

.addBoth(f, opt_scope)

Inherited from goog.async.Deferred .

Registers a function as both callback and errback.

f {!Function}
The function to be called on any result.
opt_scope {Object=}
An optional scope to call the callbacks in.
returns {!goog.async.Deferred}
The deferred object for chaining.

.addCallback(cb, opt_scope)

Inherited from goog.async.Deferred .

Register a callback function, to be called when a successful result is available.

cb {!Function}
The function to be called on a successful result.
opt_scope {Object=}
An optional scope to call the callback in.
returns {!goog.async.Deferred}
The deferred object for chaining.

.addCallbacks(cb, eb, opt_scope)

Inherited from goog.async.Deferred .

Registers a callback function and errback function.

cb {Function}
The function to be called on a successful result.
eb {Function}
The function to be called on an unsuccessful result.
opt_scope {Object=}
An optional scope to call the callbacks in.
returns {!goog.async.Deferred}
The deferred object for chaining.

.addErrback(eb, opt_scope)

Inherited from goog.async.Deferred .

Register a callback function, to be called if this operation fails.

eb {!Function}
The function to be called on an unsuccessful result.
opt_scope {Object=}
An optional scope to call the errback in.
returns {!goog.async.Deferred}
The deferred object for chaining.

.awaitDeferred(otherDeferred)

Inherited from goog.async.Deferred .

Makes this Deferred wait for otherDeferred to be called, and its preceding callbacks to be executed, before continuing with the callback sequence. This is equivalent to adding a callback that returns otherDeferred, but doesn't prevent additional callbacks from being added to otherDeferred.

otherDeferred {!goog.async.Deferred}
The Deferred to wait for.
returns {!goog.async.Deferred}
The deferred object for chaining.

.branch(opt_propagateCancel)

Inherited from goog.async.Deferred .

Create a branch off this Deferred's callback chain, and return it as a new Deferred. This means that the return value will have the value at the current point in the callback chain, regardless of any further callbacks added to this Deferred. Additional callbacks added to the original Deferred will not affect the value of any branches. All branches at the same stage in the callback chain will receive the same starting value.

opt_propagateCancel {boolean=}
If cancel() is called on every child branch created with opt_propagateCancel, the parent will be cancelled as well.
returns {!goog.async.Deferred}
The deferred value at this point in the callback chain.

.callback(opt_result)

Inherited from goog.async.Deferred .

Record a successful result for this operation, and send the result to all registered callback functions.

opt_result {*=}
The result of the operation.

.cancel(opt_deepCancel)

Inherited from goog.async.Deferred .

Cancels a deferred that has not yet received a value. If this Deferred is paused waiting for a chained Deferred to fire, the chained Deferred will also be cancelled. If this Deferred was created by calling branch() on a parent Deferred with opt_propagateCancel set to true, the parent may also be cancelled. If opt_deepCancel is set, cancel() will be called on the parent (as well as any other ancestors if the parent is also a branch). If one or more branches were created with opt_propagateCancel set to true, the parent will be cancelled if cancel() is called on all of those branches.

opt_deepCancel {boolean=}
If true, cancels this Deferred's parent even if cancel() hasn't been called on some of the parent's branches. Has no effect on a branch without opt_propagateCancel set to true.

.chainDeferred(otherDeferred)

Inherited from goog.async.Deferred .

Adds another deferred to the end of this deferred's processing chain. Use this when you want otherDeferred to be called at the end of thisDeferred's previous callbacks.

otherDeferred {!goog.async.Deferred}
The Deferred to chain.
returns {!goog.async.Deferred}
The deferred object for chaining.

.errback(opt_result)

Record that this operation failed with an error, and send the error to all registered errback functions.

opt_result {*=}
The error result of the operation.

.gatherResults(list)

Creates a DeferredList that gathers results from multiple Deferred inputs. If all inputs succeed, the callback is fired with the list of results as a flat array. If any input fails, the errback is fired with the error.

list {!Array.<!goog.async.Deferred>}
The list of deferred objects to wait for.
returns {!goog.async.DeferredList}
A new deferred list.

.hasFired()

Inherited from goog.async.Deferred .

returns {boolean}
Whether callback or errback has been called on this deferred.