javascript - async.queue 在kill 之后,无法第二次执行对列,前端妹子刚用async.queue
天蓬老师
天蓬老师 2017-04-11 09:58:02
[JavaScript讨论组]

async.queue 点击事件,kill()执行后,执行async,queue,点击第二次,kill()不执行,也不执行async.queue,怎么回事
就是这个库

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复(2)
PHP中文网

代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>爬虫小测试</title>
<meta name="description" content="">
<meta name="keywords" content="">
<script src="./jquery-2.2.1.min.js"></script>
<script src="./async.min.js"></script>
<style>
    * {
        padding: 0;
        margin: 0;
        box-sizing: border-box;
    }
    .container {
        width: 500px;
        margin: 30px auto;
        text-align: center;
    }
    .result {
        border: 1px solid #9E9E9E;
        height: 300px;
        overflow: auto;
        margin-bottom: 30px;
    }
    .btn {
        color: white;
        font-weight: 300;
        font-size: 16px;
        background-color: #7B72E9;
        border-color: #7B72E9;
        text-decoration: none;
        text-align: center;
        line-height: 40px;
        height: 40px;
        padding: 0 40px;
        margin: 0;
        border-radius: 200px;
        display: inline-block;
        appearance: none;
        cursor: pointer;
        border: none;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        -webkit-transition-property: all;
        transition-property: all;
        -webkit-transition-duration: .3s;
        transition-duration: .3s;
    }
</style>
</head>
<body>
    <p class="container">
        <p class="result">
            
        </p>
        <p class="btn" id="scratch">
            抓取
        </p>
    </p>

    <script>
        $(function () {
            // create a queue object with concurrency 2
             var q = async.queue(function(task, callback) {
                  console.log('hello ' + task.name);
                  callback('some thing wrong');
              }, 2);

             // assign a callback
             q.drain = function() {
                  console.log('all items have been processed');
              };

            $('#scratch').click(function() {
                // add some items to the queue
                q.push({name: 'foo'}, function(err) {
                    if(err) {
                        console.log(err);
                    } else {
                        console.log('finished processing foo');
                    }
                });

                q.push({name: 'bar'}, function (err) {
                    if(err) {
                        console.log(err);
                        q.kill();
                    } else {
                        console.log('finished processing bar');
                    }
                });

                q.push({name: 'meng'}, function (err) {
                    if(err) {
                        console.log(err);
                    } else {
                        console.log('finished processing meng');
                    }
                });
            });
        });
    </script>
</body>
</html>
黄舟

直接给你api。或许你会找到你要的答案,看看kill()做的事情

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号