您的位置:首页 > 其它

透传消息堆积一种处理方案demo

2015-10-12 08:57 281 查看
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
</style>
</head>
<body>
test
</body>
<script type="text/javascript">

var timeout1;
var count = 0;

testTimeout();

function testTimeout(){
timeout1 = setTimeout(function(){
console.log('setTimeout:' + new Date());
}, 5000);
}

var timer2 = setInterval(function(){
clearTimeout(timeout1);
console.log('clearTimeout:' + new Date());
testTimeout();
if(++count >= 3){
console.log(count);
clearInterval(timer2);
}
}, 2000);

</script>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: