批处理陷入循环

时间:2017-05-18 13:53:04

标签: node.js batch-processing

function amountDownloader(start, end, callback) {
    var callbackCounter = 0;
    for (var i = start; i !== end; i++) {
        console.log(i);
        (downloader(links[i], function () {
            callbackCounter++;
            if (callbackCounter === end) {
                callback();
            }
        });
    }
}

function downloadFirst(callback) {
    var amountDownloaded = 0;
    var batches = [];
    batches.push(0);
    console.log("\n\nStarted Download");
    process.stdout.write("Downloaded 0 Songs");

    //Organize In 30 30 Parts
    for (var i = 0; i !== links.length; i++) {
        if ((i + 1) % batchSize == 0) {
            batches.push(i);
        } else if ((i + 1) % batchSize !== 0 && (links.length - (i + 1)) <= 0) {
            batches.push(i);
        }
    }
    //Organize In 30 30 Parts
    do {
        amountDownloader(batches[amountDownloaded], batches[amountDownloaded + 1], function () {
            console.log("\nDownloaded " + (amountDownloaded + 1) + " Batches \n")
            amountDownloaded++
        });
    } while (amountDownloaded !== batches.length);
}

我遇到了问题{}。我想要做的是让函数amountDownloader完成,当被回调时将+1变量amountDownloded然后继续循环。

任何人都可以帮我吗?

0 个答案:

没有答案