Greasy Fork is available in English.

Task_Array_Util

//https://stackoverflow.com/questions/15504921/asynchronous-loop-of-jquery-deferreds-promises?answertab=votes#tab-top

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greasyfork.org/scripts/404464/812494/Task_Array_Util.js

//slightly modified from
//https://stackoverflow.com/questions/15504921/asynchronous-loop-of-jquery-deferreds-promises?answertab=votes#tab-top

/*
TODO Description
 */

var time = Math.floor(Math.random() * 3000);

function doTask(taskNum, next) {
    log("doTask Enter");
    setTimeout(function () {
        log(taskNum);
        next();
    }, time)
}

function createTask(taskNum){
	log("createTask Enter");
    return function(next){
        doTask(taskNum, next);
    }
}

function queueTask(tasks) {
    log("queueTask Enter!");
	log(tasks);
    //tasks is an array of functions
    for (var i = 0; i < tasks.length; i++) {
		log("queueTask i " + i);
        $(document).queue('tasks', createTask(tasks[i]));
    }

    $(document).queue('tasks', function () {
        log("All tasks dequeued");
    });
	
	dequeueTask();
}

function dequeueTask() {
    log("dequeueTask Enter");
    $(document).dequeue('tasks');
}