<commit_before>/**
 * Responsible for sequentially executing requests
 */

var async = require('async')
  , queue
  ;

executor = async.queue(function (task, cb) {
  var callback
    , lastArg = task.arguments[task.arguments.length - 1]
    ;

  // Always tell the queue task is complete. Execute callback if any was given.
  if (typeof lastArg === 'function') {
    callback = function () {
      lastArg(arguments);
      cb();
    };

    task.arguments[task.arguments.length - 1] = callback;
  } else {
    callback = function () {
      cb();
    };

    task.arguments.push(callback);
  }

  task.fn.apply(task.this, task.arguments);
}, 1);


function test1 (msg, cb) {
  var callback = cb || function () {};

  console.log("ooooo TEST1");

  setTimeout(function () {
    console.log("Hello " + msg);
    callback();
  }, 1500);
}


function test2 (msg, cb) {
  var callback = cb || function () {};

  console.log("ooooo TEST2");

  setTimeout(function () {
    console.log("Ola " + msg);
    callback();
  }, 500);
}

function bloup () { console.log("FINISHED"); }

executor.push({ this: null, fn: test1, arguments: [ 'world' ] });
executor.push({ this: null, fn: test2, arguments: [ 'world', bloup ] });


/*
 *
queue(worker, concurrency)

Creates a queue object with the specified concurrency. Tasks added to the queue will be processed in parallel (up to the concurrency limit). If all workers are in progress, the task is queued until one is available. Once a worker has completed a task, the task's callback is called.

Arguments

worker(task, callback) - An asynchronous function for processing a queued task, which must call its callback(err) argument when finished, with an optional error as an argument.
concurrency - An integer for determining how many worker functions should be run in parallel.
Queue objects

The queue object returned by this function has the following properties and methods:

length() - a function returning the number of items waiting to be processed.<commit_msg>Executor works with arguments<commit_after>/**
 * Responsible for sequentially executing requests
 */

var async = require('async')
  , queue
  ;

executor = async.queue(function (task, cb) {
  var callback
    , lastArg = task.arguments[task.arguments.length - 1]
    ;

  // Always tell the queue task is complete. Execute callback if any was given.
  if (typeof lastArg === 'function') {
    callback = function () {
      lastArg.apply(null, arguments);
      cb();
    };

    task.arguments[task.arguments.length - 1] = callback;
  } else {
    callback = function () {
      cb();
    };

    task.arguments.push(callback);
  }

  task.fn.apply(task.this, task.arguments);
}, 1);


function test1 (msg, cb) {
  var callback = cb || function () {};

  console.log("ooooo TEST1");

  setTimeout(function () {
    console.log("Hello " + msg);
    callback();
  }, 1500);
}


function test2 (msg, cb) {
  var callback = cb || function () {};

  console.log("ooooo TEST2");

  setTimeout(function () {
    console.log("Ola " + msg);
    callback('YEAH');
  }, 500);
}

function bloup () { console.log("FINISHED"); console.log(arguments); }

executor.push({ this: null, fn: test1, arguments: [ 'world' ] });
executor.push({ this: null, fn: test2, arguments: [ 'world', bloup ] });


/*
 *
queue(worker, concurrency)

Creates a queue object with the specified concurrency. Tasks added to the queue will be processed in parallel (up to the concurrency limit). If all workers are in progress, the task is queued until one is available. Once a worker has completed a task, the task's callback is called.

Arguments

worker(task, callback) - An asynchronous function for processing a queued task, which must call its callback(err) argument when finished, with an optional error as an argument.
concurrency - An integer for determining how many worker functions should be run in parallel.
Queue objects

The queue object returned by this function has the following properties and methods:

length() - a function returning the number of items waiting to be processed.
{'fraction_non_alphanumeric': 0.11958661417322834, 'fraction_numerical': 0.007874015748031496, 'mean_word_length': 3.546979865771812, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '3167085', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1133, 'n_words': 438}