Fork me on GitHub
Show:

PromiseQueue

Summary

PromiseQueue Queues and executes asynchronous functions in sequential order.

Functions added to the queue must return an Promise object. Each function will only be executed after the previous function's promise has resolved.

Example: function asyncMethod(endpoint) { var promise = new Promise(); jsonp.get(endpoint).done(promise.resolve, promise); return promise; }

var pq = new PromiseQueue(); pq.queue(asyncMethod('firstEndpoint')); pq.queue(asyncMethod('secondEndpoint')); // will not call method until first method resolves

pq.dequeue(); // starts running the queue

Constructor

aeris.PromiseQueue

Syntax

aeris.PromiseQueue

()

Summary

Methods

addResolutionArgs_

Syntax

addResolutionArgs_

(
  • args
)
private

Summary

Parameters:

clearResolutionArgs_

Syntax

clearResolutionArgs_

() private

Summary

dequeue

Syntax

dequeue

(
  • opt_options
)
Promise

Summary

Begin executing the queue.

Parameters:

  • opt_options Object=
    • break Boolean=

      Whether to stop the queue when a promise is rejected. Defaults to false.

Returns:

Promise:

Promise to complete execution of the queue including all component promises.

isRunning

Syntax

isRunning

() Boolean

Summary

Returns:

Boolean:

Is the queue executing?

queue

Syntax

queue

(
  • fn
  • opt_ctx
)

Summary

Add a function to the queue

Parameters:

stop

Syntax

stop

()

Summary

Stops execution of the queue

Properties

isRunning_

Syntax

isRunning_

Boolean private

Summary

Whether or not the queue should continue executing functions.

queueStack_

Syntax

queueStack_

Array. private

Summary

A set of functions to execute. In the format: [ [fnToExecute, context, promiseToResolveFn], ... ]

resolutionArgs_

Syntax

resolutionArgs_

Array private

Summary

Arguments with which queue promises have been resolved/rejected.