Thursday, 18 May 2017

Batch Processing stuck in loop

function amountDownloader(start, end, callback) {
    var callbackCounter = 0;
    for (var i = start; i !== end; i++) {
        console.log(i);
        finish (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.lenght);
}

I am having a problem with the do while{}. What I want to do is let the function amountDownloader finish, when called back will +1 the var amountDownloded and then, continue the loop.

Can anyone help me with this?



via Jamie Stivala

No comments:

Post a Comment