async.DeferredList Extends goog.async.Deferred
Constructs an object that waits on the results of multiple asynchronous operations and marshals the results. It is itself a Deferred, and may have an execution sequence of callback functions added to it. Each DeferredList instance is single use and may be fired only once. The default behavior of a DeferredList is to wait for a success or error result from every Deferred in its input list. Once every result is available, the DeferredList's execution sequence is fired with a list of [success, result] array pairs, where success is a boolean indicating whether result was the product of a callback or errback. The list's completion criteria and result list may be modified by setting one or more of the boolean options documented below. Deferred instances passed into a DeferredList are independent, and may have additional callbacks and errbacks added to their execution sequences after they are passed as inputs to the list.

Inheritance

Constructor

goog.async.DeferredList(listopt_fireOnOneCallbackopt_fireOnOneErrbackopt_consumeErrorsopt_canceleropt_defaultScope)

Parameters

list : !Array.<!goog.async.Deferred>
An array of deferred results 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 successful result.
opt_fireOnOneErrback : boolean=
Whether to stop waiting as soon as one input reports an error. The failing result is passed to the DeferredList's errback sequence.
opt_consumeErrors : boolean=
When true, any errors fired by a Deferred in the input list will be captured and replaced with a succeeding null result. Any callbacks added to the Deferred after its use in the DeferredList will receive null instead of the error.
opt_canceler : Function=
A function that will be called if the DeferredList is canceled. @see goog.async.Deferred#cancel
opt_defaultScope : Object=
The default scope to invoke callbacks or errbacks in.

Instance Methods

Public Protected Private
errback()
No description.
code »
handleCallback_(indexsuccessresult) *
Registers the result from an input deferred callback or errback. The result is returned and may be passed to additional handlers in the callback chain.
Arguments:
index : number
The index of the firing deferred object in the input list.
success : boolean
Whether the result is from a callback or errback.
result : *
The result of the callback or errback.
Returns: *  The result, to be handled by the next handler in the deferred's callback chain (if any). If consumeErrors is set, an error result is replaced with null.
code »
addBoth(fopt_scope) !goog.async.Deferred
Registers one function as both a callback and errback.
Arguments:
f : !?function(this:T,):?
The function to be called on any result.
opt_scope : T=
An optional scope to call the function in.
Returns: !goog.async.Deferred  This Deferred.
code »
addCallback(cbopt_scope) !goog.async.Deferred
Register a callback function to be called with a successful result. If no value is returned by the callback function, the result value is unchanged. If a new value is returned, it becomes the Deferred result and will be passed to the next callback in the execution sequence. If the function throws an error, the error becomes the new result and will be passed to the next errback in the execution chain. If the function returns a Deferred, the execution sequence will be blocked until that Deferred fires. Its result will be passed to the next callback (or errback if it is an error result) in this Deferred's execution sequence.
Arguments:
cb : !function(this:T,VALUE):?
The function to be called with a successful result.
opt_scope : T=
An optional scope to call the callback in.
Returns: !goog.async.Deferred  This Deferred.
code »
addCallbacks(cbebopt_scope) !goog.async.Deferred
Registers a callback function and an errback function at the same position in the execution sequence. Only one of these functions will execute, depending on the error state during the execution sequence. NOTE: This is not equivalent to def.addCallback().addErrback()! If the callback is invoked, the errback will be skipped, and vice versa.
Arguments:
cb : (function(this:T,VALUE):?) | null
The function to be called on a successful result.
eb : (?function(this:T,):?) | null
The function to be called on an unsuccessful result.
opt_scope : T=
An optional scope to call the functions in.
Returns: !goog.async.Deferred  This Deferred.
code »
addErrback(ebopt_scope) !goog.async.Deferred.<VALUE>
Register a callback function to be called with an error result. If no value is returned by the function, the error result is unchanged. If a new error value is returned or thrown, that error becomes the Deferred result and will be passed to the next errback in the execution sequence. If the errback function handles the error by returning a non-error value, that result will be passed to the next normal callback in the sequence. If the function returns a Deferred, the execution sequence will be blocked until that Deferred fires. Its result will be passed to the next callback (or errback if it is an error result) in this Deferred's execution sequence.
Arguments:
eb : !?function(this:T,):?
The function to be called on an unsuccessful result.
opt_scope : T=
An optional scope to call the errback in.
Returns: !goog.async.Deferred.<VALUE>  This Deferred.
code »
assertNotDeferred_(obj)
Asserts that an object is not a Deferred.
Arguments:
obj : *
The object to test.
code »
awaitDeferred(otherDeferred) !goog.async.Deferred
Makes this Deferred wait for another Deferred's execution sequence to complete before continuing. This is equivalent to adding a callback that returns otherDeferred, but doesn't prevent additional callbacks from being added to otherDeferred.
Arguments:
otherDeferred : !goog.async.Deferred | !goog.Thenable
The Deferred to wait for.
Returns: !goog.async.Deferred  This Deferred.
code »
branch(opt_propagateCancel) !goog.async.Deferred.<VALUE>
Creates a branch off this Deferred's execution sequence, and returns it as a new Deferred. The branched Deferred's starting result will be shared with the parent at the point of the branch, even if further callbacks are added to the parent. All branches at the same stage in the execution sequence will receive the same starting value.
Arguments:
opt_propagateCancel : boolean=
If cancel() is called on every child branch created with opt_propagateCancel, the parent will be canceled as well.
Returns: !goog.async.Deferred.<VALUE>  A Deferred that will be started with the computed result from this stage in the execution sequence.
code »
branchCancel_()
Handle a single branch being canceled. Once all branches are canceled, this Deferred will be canceled as well.
code »
callback(opt_result)
Fire the execution sequence for this Deferred by passing the starting result to the first registered callback.
Arguments:
opt_result : VALUE=
The starting result.
code »
cancel(opt_deepCancel)
Cancels a Deferred that has not yet been fired, or is blocked on another deferred operation. If this Deferred is waiting for a blocking Deferred to fire, the blocking Deferred will also be canceled. If this Deferred was created by calling branch() on a parent Deferred with opt_propagateCancel set to true, the parent may also be canceled. 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 canceled if cancel() is called on all of those branches.
Arguments:
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.
code »
chainDeferred(otherDeferred) !goog.async.Deferred
Links another Deferred to the end of this Deferred's execution sequence. The result of this execution sequence will be passed as the starting result for the chained Deferred, invoking either its first callback or errback.
Arguments:
otherDeferred : !goog.async.Deferred
The Deferred to chain.
Returns: !goog.async.Deferred  This Deferred.
code »
check_()
Verifies that the Deferred has not yet been fired.
code »
continue_(isSuccessres)
Called after a blocking Deferred fires. Unblocks this Deferred and resumes its execution sequence.
Arguments:
isSuccess : boolean
Whether the result is a success or an error.
res : *
The result of the blocking Deferred.
code »
errback(opt_result)
Fire the execution sequence for this Deferred by passing the starting error result to the first registered errback.
Arguments:
opt_result : *=
The starting error.
code »
fire_()
Exhausts the execution sequence while a result is available. The result may be modified by callbacks or errbacks, and execution will block if the returned result is an incomplete Deferred.
code »
hasErrback_() boolean
No description.
Returns: boolean  Whether an errback exists in the remaining sequence.
code »
hasFired() boolean
No description.
Returns: boolean  Whether the execution sequence has been started on this Deferred by invoking callback or errback.
code »
isError(res) boolean
No description.
Arguments:
res : *
The latest result in the execution sequence.
Returns: boolean  Whether the current result is an error that should cause the next errback to fire. May be overridden by subclasses to handle special error types.
code »
makeStackTraceLong_(error)
Attempt to make the error's stack trace be long in that it contains the stack trace from the point where the deferred was created on top of the current stack trace to give additional context.
Arguments:
error : *
No description.
code »
then()
Implements for seamless integration with . Deferred results are mutable and may represent multiple values over their lifetime. Calling then on a Deferred returns a Promise with the result of the Deferred at that point in its callback chain. Note that if the Deferred result is never mutated, and only then calls are made, the Deferred will behave like a Promise.
code »
updateResult_(isSuccessres)
Updates the current result based on the success or failure of the last action in the execution sequence.
Arguments:
isSuccess : boolean
Whether the new result is a success or an error.
res : *
The result.
code »

Instance Properties

constructor :
No description.
Code »
consumeErrors_ :
Whether to stop error propagation on the input Deferred objects. If the DeferredList sees an error from one of the Deferred inputs, the error will be captured, and the Deferred will be returned to success state with a null return value.
Code »
deferredResults_ :
The stored return values of the Deferred objects.
Code »
fireOnOneCallback_ :
Whether to fire on the first successful callback instead of waiting for every Deferred to complete.
Code »
fireOnOneErrback_ :
Whether to fire on the first error result received instead of waiting for every Deferred to complete.
Code »
list_ :
The list of Deferred objects to wait for.
Code »
numFinished_ :
The number of input deferred objects that have fired.
Code »
blocked_ :
Whether the Deferred is blocked waiting on another Deferred to fire. If a callback or errback returns a Deferred as a result, the execution sequence is blocked until that Deferred result becomes available.
Code »
blocking_ :
Whether this Deferred is blocking execution of another Deferred. If this instance was returned as a result in another Deferred's execution sequence,that other Deferred becomes blocked until this instance's execution sequence completes. No additional callbacks may be added to a Deferred once it is blocking another instance.
Code »
branches_ :
The number of Deferred objects that have been branched off this one. This will be decremented whenever a branch is fired or canceled.
Code »
constructorStack_ :
Holds the stack trace at time of deferred creation if the JS engine provides the Error.captureStackTrace API.
Code »
defaultScope_ :
The default scope to execute callbacks and errbacks in.
Code »
fired_ :
Whether the Deferred has been fired.
Code »
hadError_ :
Whether the last result in the execution sequence was an error.
Code »
onCancelFunction_ :
Optional function that will be called if the Deferred is canceled.
Code »
If this Deferred was created by branch(), this will be the "parent" Deferred.
Code »
result_ :
The current Deferred result, updated as callbacks and errbacks are executed.
Code »
sequence_ :
Entries in the sequence are arrays containing a callback, an errback, and an optional scope. The callback or errback in an entry may be null.
Code »
silentlyCanceled_ :
Whether the Deferred has been canceled without having a custom cancel function.
Code »
unhandledErrorId_ :
If an error is thrown during Deferred execution with no errback to catch it, the error is rethrown after a timeout. Reporting the error after a timeout allows execution to continue in the calling context (empty when no error is scheduled).
Code »

Static Methods

goog.async.DeferredList.gatherResults(list) !goog.async.Deferred
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 list's errback is fired immediately with the offending error, and all other pending inputs are canceled.
Arguments:
list : !Array.<!goog.async.Deferred>
The list of Deferred inputs to wait for.
Returns: !goog.async.Deferred  The deferred list of results from the inputs if they all succeed, or the error result of the first input to fail.
code »

Static Properties

goog.async.DeferredList.superClass_ :
No description.
Code »

Package async

Package Reference