游戏编程研究院pomelo 游戏开发

setTimeout 和 setInterval 结合使用

2014-11-21  本文已影响337人  抓不住的风

var async = require('async'); 

 var setTimeoutIds = function(){

 var timeoutIds; 

 var timeoutId; 

 var intervalId;

 timeoutId = setTimeout(function(){ 

      async.waterfall([ 

               function(cb){ 

                     intervalId = setInterval(function(){ 

                          console.log('-----intervalId'); 

                     },2000); 

                     cb();

                },

                function(cb){ 

                     console.log('intervalId=====',intervalId); 

                     cb(); 

                }

        ],function(err,info){ 

            console.log('endendendendend');

       });

 },5000); 

 console.log('timeoutId',timeoutId); 

}

 setTimeoutIds(); 

 这样才能获取到intervalId 

 如果是这样用的话 

timeoutId = setTimeout(function(){ 

         intervalId = setInterval(function(){ },2000);

 },5000); 

只能获取到timeoutId 而intervalId 是undefined

上一篇下一篇

猜你喜欢

热点阅读