Clear Up
SharpKit Reference

TaskRunner Class

Provides the ability to execute one or more arbitrary tasks in a asynchronous 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 runner = new Ext.util.TaskRunner();
           var task = runner.start({
           run: updateClock,
           interval: 1000
           }
            

The equivalent using TaskManager:

  
var task = Ext.TaskManager.start({
           run: updateClock,
           interval: 1000
           });
            

To end a running task:

  
    Ext.TaskManager.stop(task);
            

If a task needs to be started and stopped repeated over time, you can create a Task instance.

  
var task = runner.newTask({
           run: function () {
           // useful code
           },
           interval: 1000
           });
           task.start();
           // ...
           task.stop();
           // ...
           task.start();
            

A re-usable, one-shot task can be managed similar to the above:

  
var task = runner.newTask({
           run: function () {
           // useful code to run once
           },
           repeat: 1
           });
           task.start();
           // ...
           task.start();
            

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

Also see Ext.util.DelayedTask.

Namespace: Ext.util

Base Types

Derived Types

Constructors

Name Description
TaskRunner(object) Parameters
  • interval : Number/Object (optional)

    The minimum precision in milliseconds supported by this TaskRunner instance. Alternatively, a config object to apply to the new instance.

    Defaults to: 10

  • TaskRunner(TaskRunnerConfig)
    TaskRunner(Object[])

    Fields

    Name Description
    interval The timer resolution. Defaults to: 10

    Methods

    Name Description
    newTask(object) Creates a new Task instance. These instances can be easily started and stopped.
    start(object) Starts a new task. Before each invocation, Ext injects the property taskRunCount into the task object so that calculations based on the repeat count can be performed. The returned task will contain a destroy method that can be used to destroy the task and cancel further calls. This is equivalent to the stop method.
    stop(object) Stops an existing running task.
    stopAll() Stops all tasks that are currently running.
    © Copyright 2005-2011 SharpKit. All rights reserved.