<commit_before><commit_msg>create jQuery.ajaxPool plugin<commit_after>/*
 * jQuery ajaxPool plugin
 *
 * @author <NAME>
 * @license MIT
 * @link https://github.com/keradus/jQuery.ajaxPool
 * @version 1.0.0
 */

/*jslint plusplus: true */
/*globals jQuery */

(function ($) {
    "use strict";

    $.ajaxPool = function (q) {
        var i, limit, processNextTask, promise, task, taskAbort, taskProcess, tasks, tasksLength;

        processNextTask = function () {
            if (tasks.length) {
                tasks.shift().taskProcess();
            }
        };

        taskProcess = function () {
            var callbacks;

            callbacks = {
                done: this.taskOpts.success,
                fail: this.taskOpts.error,
                always: this.taskOpts.complete
            };
            this.taskOpts.success = this.taskOpts.error = this.taskOpts.complete = undefined;

            this.taskAjax = $.ajax(this.taskOpts).done(callbacks.done).fail(callbacks.fail).always(callbacks.always);
            this.taskAjax.then(this.resolve, this.reject);
        };

        taskAbort = function () {
            if (this.taskAjax) {
                this.taskAjax.abort();
            }
        };

        tasks = [];
        tasksLength = q.tasks.length;
        for (i = 0; i < tasksLength; ++i) {
            task = new $.Deferred();
            task.taskId = i;
            task.taskOpts = q.tasks[i];
            task.taskProcess = taskProcess;
            task.taskAjax = null;
            task.taskAbort = taskAbort;
            task.always(processNextTask);

            tasks[i] = task;
        }

        promise = $.when.apply(this, tasks);

        if (q.success) {
            promise.done(q.success);
        }
        if (q.error) {
            promise.fail(q.error);
        }
        if (q.complete) {
            promise.always(q.complete);
        }

        limit = Math.min(q.limit, tasksLength);
        for (i = 0; i < limit; ++i) {
            processNextTask();
        }

        return promise;
    };
}(jQuery));
{'fraction_non_alphanumeric': 0.13262342691190707, 'fraction_numerical': 0.002420135527589545, 'mean_word_length': 1.58375, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6049800', 'n_tokens_mistral': 616, 'n_tokens_neox': 607, 'n_words': 114}