Yahoo! UI Library

queue  3.0.0pr2

Yahoo! UI Library > queue > Queue
Search:
 
Filters

Class Queue

Mechanism to execute a series of callbacks in a non-blocking queue. Each callback is executed via setTimout unless configured with a negative timeout, in which case it is run in blocking mode in the same execution thread as the previous callback. Callbacks can be function references or object literals with the following keys:
  • fn - {Function} REQUIRED the callback function.
  • timeout - {number} millisecond delay to wait after previous callback completion before executing this callback. Negative values cause immediate blocking execution. Default 0.
  • until - {Function} boolean function executed before each iteration. Return true to indicate callback completion.
  • iterations - {Number} number of times to execute the callback before proceeding to the next callback in the queue. Incompatible with until.

Constructor

Queue ( callback* )
Parameters:
callback* <Function|Object> Any number of callbacks to initialize the queue

Properties

id - protected {number}

Timeout id used to pause or stop execution and indicate the execution state of the Queue. 0 indicates paused or stopped, negatives indicate blocking execution, and positives indicate non-blocking execution.

q - protected {Array}

The callback queue

Methods

_exec

protected void _exec ( fn , c )
Executes the callback function
Parameters:
fn <Function> the function to execute
c <Object|Function> the callback as defined during add(c)
Returns: void

_shift

private void _shift ( )
Shifts the first callback off the Queue
Returns: void

add

Queue add ( callback* )
Add any number of callbacks to the end of the queue
Parameters:
callback* <Function|Object> Any number of callbacks
Returns: Queue
the Queue instance

pause

Queue pause ( )
Pause the execution of the Queue after the execution of the current callback completes. If called from code outside of a queued callback, clears the timeout for the pending callback. Paused Queue can be restarted with q.run()
Returns: Queue
the Queue instance

run

Queue run ( )
Execute the queue callbacks (also resumes paused Queue).
Returns: Queue
the Queue instance

stop

Queue stop ( )
Stop and clear the Queue's queue after the current execution of the current callback completes.
Returns: Queue
the Queue instance

Events

addCallback

addCallback ( callbacks )
Fired from within add(..) after callbacks are queued
Parameters:
callbacks <Array> Array of callbacks passed to add(..)

afterCallback

afterCallback ( o )
Fired before a callback is executed
Parameters:
o <Object> Object literal with the following keys:
fn
The function just executed
callback
The callback as provided to add(..)

beforeCallback

beforeCallback ( o )
Fired before a callback is executed
Parameters:
o <Object> Object literal with the following keys:
fn
The function about to be executed
callback
The callback as provided to add(..)

end

end ( )
Event fired after the last queued callback is executed. Not fired if the Queue is stopped via q.stop().

pause

pause ( )
Fired after Queue is paused

shiftCallback

shiftCallback ( callback )
Fired after a callback is shifted from the Queue
Parameters:
callback <Function|Object> The callback passed to add(..)

stop

stop ( )
Fired after Queue is stopped


Copyright © 2008 Yahoo! Inc. All rights reserved.