For up to date documentation and features, visit http://docs.sencha.com/ext-js/4-0

## Sencha Documentation

# Ext.util.TaskRunner

Provides the ability to execute one or more arbitrary tasks in a multithreaded manner. Generally, you can use the singleton Ext.TaskManager instead, but if needed, you can create separate instances of TaskRunner. Any number of separate tasks can be started at any time and will run independently of each other. Example usage:

    // Start a simple clock task that updates a div once per second
    var updateClock = function(){
        Ext.fly('clock').update(new Date().format('g:i:s A'));
    }
    var task = {
        run: updateClock,
        interval: 1000 //1 second
    }
    var runner = new Ext.util.TaskRunner();
    runner.start(task);

    // equivalent using TaskManager
    Ext.TaskManager.start({
        run: updateClock,
        interval: 1000
    });

See the start method for details about how to configure a task object.

Also see Ext.util.DelayedTask.

Defined By

### Methods

Ext.util.TaskRunner
view source
TaskRunner( [Number interval]) : void

### Parameters

- interval : Number

  (optional) The minimum precision in milliseconds supported by this TaskRunner instance (defaults to 10)

### Returns

- void

Ext.util.TaskRunner
view source
start( [Object task]) : Object

Starts a new task.

Starts a new task.

### Parameters

- task : Object

  A config object that supports the following properties:

  - `run` : Function

    The function to execute each time the task is invoked. The function will be called at each interval and passed the `args` argument if specified, and the current invocation count if not.

    If a particular scope (`this` reference) is required, be sure to specify it using the `scope` argument.

    Return `false` from this function to terminate the task.

  - `interval` : Number
    The frequency in milliseconds with which the task should be invoked.
  - `args` : Array
    (optional) An array of arguments to be passed to the function specified by `run`. If not specified, the current invocation count is passed.
  - `scope` : Object
    (optional) The scope (`this` reference) in which to execute the `run` function. Defaults to the task config object.
  - `duration` : Number
    (optional) The length of time in milliseconds to invoke the task before stopping automatically (defaults to indefinite).
  - `repeat` : Number
    (optional) The number of times to invoke the task before stopping automatically (defaults to indefinite).

  Before each invocation, Ext injects the property `taskRunCount` into the task object so that calculations based on the repeat count can be performed.

### Returns

- Object

  The task

Ext.util.TaskRunner
view source
stop( Object task) : Object

Stops an existing running task.

Stops an existing running task.

### Parameters

- task : Object

  The task to stop

### Returns

- Object

  The task

Ext.util.TaskRunner
view source
stopAll : void

Stops all tasks that are currently running.

Stops all tasks that are currently running.

### Returns

- void