Show:

Cancellable promise.

Constructor

A.CancellablePromise

(
  • fn
  • opt_errorCallback
)

Parameters:

  • fn Function

    A function where to insert the logic that resolves this promise. Receives fulfill and reject functions as parameters. This function is called synchronously.

  • opt_errorCallback Function

    Optional error callback to be fired whenever a cancellable promise is cancelled.

Methods

_cancelChildPromises

(
  • childPromise
  • opt_message
)
private

Cancels children Promises. If the Promise has not already been resolved, reject it with a cancel error. If there are no other children in the list of callback entries, propagate the cancellation by canceling this Promise as well.

Parameters:

  • childPromise CancellablePromise

    The Promise to cancel.

  • opt_message String

    An optional debugging message for describing the cancellation reason.

cancel

(
  • opt_message
)

Cancels the Promise by rejecting it with a A.CancellablePromise.Error. No action is performed if the Promise is already resolved.

Parameters:

  • opt_message String

    An optional debugging message for describing the cancellation reason.

thenAways

(
  • callback
)
Promise

Adds a callback that will be invoked whether the Promise is fulfilled or rejected. The callback receives no argument, and a new child Promise is created. This is useful for ensuring that cleanup takes place after certain asynchronous operations. Callbacks added with thenAlways will be executed in the same order with other calls to then, thenAlways.

Parameters:

  • callback Function

    A function that will be invoked when the Promise is resolved.

Returns:

Promise:

A new Promise that will receive the result of the callback.

thenCatch

(
  • callback
)
Promise

Adds a callback that will be invoked only if the Promise is rejected. This is equivalent to then(null, onRejected).

Parameters:

  • callback Function

    A function that will be invoked with the rejection reason if the Promise is rejected.

Returns:

Promise:

A new Promise that will receive the result of the callback.

Properties

_childPromises

Array protected

Holds the list of children promises.

_errorCallback

Function protected

Holds the Optional error callback to be fired whenever a cancellable promise is cancelled.