How to use Taskrunner and delayedtask to pass parameters to the run () method in ExtJS

Source: Internet
Author: User

The classes that support multithreading in ExtJs are Ext.util.TaskRunner and Ext.util.DelayedTask. Taskrunner provides multi-threaded timing services, Delayedtask allows you to delay how long to perform a task in a new thread. Ext.taskmgr is a Taskrunner instance, the last line in Taskmgr.js source code can be seen:

Ext.taskmgr = new Ext.util.TaskRunner ();

Essentially, whether they are taskrunner or delayedtask, they perform tasks through setinterval (), Taskrunner can repeatedly execute a method, and Delayedtask is called after a task is delayed. Clearinterval () to ensure that it is executed only once. So here's how to pass parameters to a task's run () method, which is essentially passing parameters to the SetInterval () method.

We went to http://extjs.com/deploy/dev/docs/output/Ext.util.TaskRunner.html to see the task in Taskrunner's Api,start (Object Task) A parameter is a configuration object that focuses on its two properties:

Run:function method of timing execution

Args:array the arguments passed to the Run method above

To see a basic use method, here is the use without the args attribute parameter:

01.Ext.onReady(function(){
02.    var runner = new Ext.util.TaskRunner ();
03.    runner.start({      //任务被调用的方法
04.        run:  function(){
05.            alert('run() 方法被执行.')
06.         },
07.        interval: 1000, //一秒执行一次
08.        repeat: 5        //重复执行 5 次
09.    });
10.});

Instead of providing parameters to the run () method, how do you pass the parameters to run (), and how do the run () method get the incoming parameters? The method is: The intrinsic attribute of JS function arguments. Look at the code:

01.Ext.onReady(function(){
02.    var runner = new Ext.util.TaskRunner ();
03.    runner.start({      //任务被调用的方法
04.        run:  function(){ //run 方法原型不变,实际可以去遍历这个 arguments 参数数组
05.             alert('run() 方法被执行. 传入参数个数:' + arguments.length + ", 分别是: "
06.                + arguments[0] +"," + arguments[1] +"," +  arguments[2]);
07.            return false;  //不返回 false,run() 方法 会被永无止境的调用
08.        },
09.        args:[100,200,300],
10.         interval: 1000, //一秒执行一次,本例中 run() 只在 1 秒后调用一次
11.        repeat: 2       //重复执行 2 次, 这个参数已不再启作用了
12.    });
13.});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.