Class: Promise

Stork. Promise

new Stork.Promise(context, success, failure, root)

Instantiates a new Promise.

Name Type Description
context Object

The this to apply to the success, failure, and error callbacks.

success function optional

A success callback to add to be invoked.

failure function optional

A failure callback to add to be invoked.

root Stork.Promise optional

The root promise, if one exists.

Members

staticStork.Promise.CHAINEDNumber

Promise has been marked as a success and the next promise has been notified.

staticStork.Promise.FAILURENumber

Promise has been marked as a failure.

staticStork.Promise.PENDINGNumber

Promise is awaiting for a success or failure notification.

staticStork.Promise.SUCCESSNumber

Promise has been marked as a success.

argsArray

An array of arguments that are to be passed to the success or failure callbacks.

chainFailureResultboolean

Whether this promise should look at the result of the failure callbacks for a promise to bind to and continue the chain.

contextObject

The this to apply to the callbacks.

errorsArray.<function()>

An array of error callbacks stored at the root promise.

failuresArray.<function()>

An array of failure callbacks to invoke when the promise is marked as failed.

nextPromise

The next promise in the chain of promises.

rootPromise

The root promise in the chain of promises.

stateNumber

The current state of this promise.

Default Value:
  • Promise.PENDING

successesArray.<function()>

An array of success callbacks to invoke when the promise is marked as successful.

Methods

staticStork.Promise.Done(context){Stork.Promise}

Creates a Promise that has already successfully ran.

Name Type Description
context Object

The this to apply to the success, failure, and error callbacks.

Returns:
promise created.

staticStork.Promise.Group(groupSize, context, success, failure)

Creates a Promise that waits for a given number of success to be considered a success, any failure will cause subsequent successes to be ignored.

Name Type Description
groupSize Number

The number of $success calls that need to be made for the promise to actually be considered a success.

context Object

The this to apply to the success, failure, and error callbacks.

success function optional

A success callback to add to be invoked.

failure function optional

A failure callback to add to be invoked.

Adds a callback to be invoked when either a success or failure occurs on this promise. If a promise is returned by the callback - once that promise completes the next promise will be processed on either success or failure.

Name Type Description
complete function

The function to invoke when either a success or a failure occurs.

Returns:
class="prettyprint source"> The next promise to invoke when the returned promise from the success callback finishes.

Adds a generic error to be called if any of the promises in the chain have failed.

Name Type Description
error function

A function to invoke if any of the promises fail.

Returns:
A reference to this promise.

then(success, failure){Stork.Promise}

Adds success and optionally a failure callback to be invoked when the promised operation completes. The success callback can return a promise to chain promises.

Name Type Description
success function

The function to invoke with the success arguments.

failure function optional

The function to invoke with the failure arguments.

Returns:
The next promise to invoke when the returned promise from the success callback finishes.