# Yahoo! UI Library

### DataTable Widget 2.8.2r1

Yahoo! UI Library > datatable > YAHOO.util.Chain
Search:
Filters
Show Private Show Protected Show Deprecated

## Class YAHOO.util.Chain

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:

- `method` - {Function} REQUIRED the callback function.
- `scope` - {Object} the scope from which to execute the callback. Default is the global window scope.
- `argument` - {Array} parameters to be passed to method as individual arguments.
- `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 completion and proceed to the next callback.
- `iterations` - {Number} number of times to execute the callback before proceeding to the next callback in the chain. Incompatible with `until`.

### Constructor

YAHOO.util.Chain `( callback* )`

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

### Properties

#### id - `private {number}`

Timeout id used to pause or stop execution and indicate the execution state of the Chain. 0 indicates paused or stopped, -1 indicates blocking execution, and any positive number indicates non-blocking execution.

#### q - `private {Array}`

The callback queue

### Methods

#### add

`Chain add ( c )`
Add a callback to the end of the queue

Parameters:
  `c <Function|Object>` the callback function ref or object literal

Returns: `Chain`
  the Chain instance

#### pause

`Chain pause ( )`
Pause the execution of the Chain after the current execution of the current callback completes. If called interstitially, clears the timeout for the pending callback. Paused Chains can be restarted with chain.run()

Returns: `Chain`
  the Chain instance

#### run

`Chain run ( )`
Begin executing the chain, or resume execution from the last paused position.

Returns: `Chain`
  the Chain instance

#### stop

`Chain stop ( )`
Stop and clear the Chain's queue after the current execution of the current callback completes.

Returns: `Chain`
  the Chain instance

### Events

#### end

`end ( )`
Event fired when the callback queue is emptied via execution (not via a call to chain.stop().

Copyright © 2010 Yahoo! Inc. All rights reserved.