Task_Array_Util

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

Від 01.06.2020. Дивіться остання версія.

Цей скрипт не слід встановлювати безпосередньо. Це - бібліотека для інших скриптів для включення в мета директиву // @require https://update.greasyfork.org/scripts/404464/811186/Task_Array_Util.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

//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 () {
        doTask(taskNum, dequeueTask);
    }
}

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

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

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